/** * insertionsort.cpp * 30apr07/sklar * * this program demonstrates the insertion sort algorithm. * */ #include #include #include using namespace std; // declare constants const int NUM_DICE = 5; // declare global variable int dice[NUM_DICE]; // declare function prototypes void initDice(); void printDice( int d[], int n ); void insertionSort(); /** * initDice() * * this function initializes the values in the array of dice to * integers between 1 and 6 * */ void initDice() { for ( int i=0; i aux[j] )) { j++; } // end while // shift entries in "aux" array to make room for new entry // (if necessary, i.e., if j < num_aux) for ( int k=num_aux; k>j; k-- ) { aux[k] = aux[k-1]; } // end for k aux[j] = dice[i]; num_aux++; num_passes++; cout << "after pass #" << num_passes << ": "; printDice( aux, num_aux ); } // end for j for ( int i=0; i