/* ************************************************************************** * Program name : 041_Insertion_sort (Version 1.00) * * Author : Duck Wong * * Language : C / C++ * * Compiler : Boodshed Dec-C++ compiler Ver 3.95 * * Computer : PII350 * * O/S : Windows 98 * ************************************************************************** * Version 1.00 : 2000/06/15 - first version * ************************************************************************** * Description : (a) Input a list of numbers * * (b) Sort the list by Insertion Sort * * (c) Try again ? * ************************************************************************** */ #include #include #include void Insertionsort(int [], const int); int main() { // part 1 : declaration int Index; // loop counter const int Arraysize=15; // Maximum no. of element 15 int Number[Arraysize]; // Define the array Number char Again; // Try again ? do { // part 2 : Input 15 real numbers cout << "\n\t\tInsertion Sort (Version 1.00)\n"; cout << "\nPlease input 15 integer numbers (1 - 99), then this program" << "\nwill printed the list in both unsorted and sorted orders.\n\n"; for (Index=1; Index<=Arraysize; Index++) do { cout << "The #" << Index << " number is : "; cin >> Number[Index-1]; } while ((Number[Index-1]<1) || (Number[Index-1]>99)); // part 3 : List in unsorted order cout << "\n\nThe unsorted list is : \n"; for (Index=1; Index<=Arraysize; Index++) cout << Number[Index-1] << ", "; // part 4 : List in sorted order cout << "\n\nThe sorted list is : \n"; Insertionsort(Number, Arraysize); for (Index=1; Index<=Arraysize; Index++) cout << Number[Index-1] << ", "; // part 5 : try another number ? cout << "\n\n\t\aTry another set of numbers (Y/N) : "; cin >> Again; cout << "\n"; }while (Again=='Y' || Again=='y'); cout << "\n" << endl; system("PAUSE"); return 0; } void Insertionsort(int Number[], int Arraysize) // Note (1) { int Index, Tempkey, Tempint; char Found; for (Index= 1; Index<=Arraysize-1; Index++) if (Number[Index]