/********************************************************************* *** FILE: test_struct_sort.cpp *** DATE: 09/28/2003 *** AUTHOR: Daniel Dementiev *** DESCRIPTION: This is just an example if the template sort. *** It can be executed without any parameter and then *** it reads the 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 specified size *** then will sort it. *** To execute the file you need to have a "dictionary *** file" - a text file with some words in it. You can *** either use the one from the web-site or any one of *** your own. *** To execute the program run: *** ...> test_struct_sort N [filename] *** where N - is the size of the array to generate *** and filename - is the name of the dictionary file. *** The second argument is optional, if it's not specified *** the program is looking for file named 'dict.txt' *** Example: *** ...> test_struct_sort 12000 *** ...> test_struct_sort 100 test_struct_sort.cpp *********************************************************************/ #include #include #include #include #include #include //#define DEBUG_OUTPUT struct TRecord { char word[16]; int value; }; int operator>(const TRecord &a, const TRecord &b) { return a.value > b.value; } void print(const TRecord &a) { cout<" defined // for these elements. // ------------------------------------- template void isort(Element data[], int N) { int i, j; Element s; for(i=1;i=0 && data[j]>s; j--){ data[j+1] = data[j]; } if( j < i-1 ) data[j+1] = s; } } void main(int argc, char *argv[]) { TRecord *data; int size, i; char word[32], fname[256]="dict.txt"; ifstream inp; if( argc > 1 ){ if( argc > 2 ){ strncpy(fname, argv[2], 255); fname[255]=0; } cout<<"Using file '"<>word && i