/********************************************************************* *** FILE: insertion_sort.cpp *** DATE: 08/22/2003 *** AUTHOR: Daniel Dementiev *** DESCRIPTION: This programm illustrates the insertion sort method. *** It can be executed without any parameter and then *** it reads teh integer array to sort from the standard *** input, or you can provide an integer number as *** the program argument. In the last case the program *** will generate a random array of the s[ecified size *** then will sort it. *********************************************************************/ #include #include #include #include #include // #define DEBUG_OUTPUT // ------------------------------------- // This function prints an integer array // "data" of the size "N" // ------------------------------------- void print_array(int data[], int N) { for(int i=0;i s ){ data[j+1] = c; j--; if( j == -1 ) break; c = data[j]; } if( j==-1 || j 1 ){ size = (size=atoi(argv[1])) ? size : 256; cout<<"Generating a random array of "<>i ){ data[size++] = i; if( size == n ){ n += 128; int *tmp = new int[n]; for(i=0;i