//addanint.cpp //Insert one height into an array //of heights. //The array is maintained in //ascending order. #include //cout using namespace std; const int maxsize=10; int main() { int height[maxsize]; //create an array of integers //the size must be a constant int j; //index height[0]=54; height[1]=60; height[2]=60; height[3]=65; height[4]=72; height[5]=78; int top=5;//offset of topmost filled entry of the list int newHeight; //data to enter into list int index_for_newHeight; //offset of location for newHeight newHeight=63; //move up bigger items j=top; while (height[j]>=newHeight && j>=0) //height[j]>=newHeight means we haven't found the right spot yet //j>=0 means we haven't reached the bottom yet. { height[j+1]=height[j]; //move item up one j--; } //found a height smaller than newHeight //or ran out of array index_for_newHeight=j+1; height[index_for_newHeight]=newHeight; //update the count top++; //display for (j=0; j<=top; j++) cout << height[j] << " "; cout << "\nThere are " << top+1 << " items in the array.\n"; cout << "newHeight is the " << index_for_newHeight+1 << "th item on the list.\n"; return 0; }