/////// File: arbsortlines.C /////// // applying arbqsort to TextLines object // // To compile: // CC arbsortl.o ../arbsort/arbqsort.o SortKey.o TxtLines.o #include #include #include "TextLines.h" #include "SortKey.h" #include "../arbsort/arbqsort.h" int keycmp(TextLines *tl, int i, int j) { extern SortKey sortkey; TextLines& txtobj= *tl; return( sortkey.cmp(txtobj[i], txtobj[j]) ); } void lineswap(TextLines *tl, int i, int j) { tl->swap(i,j); } SortKey sortkey; // default global sort key int main(int argc, String argv[]) { if (argc > 2) { cerr << "Usage: " << argv[0] << " key_position\n"; exit(1); } if (argc == 2) sortkey = SortKey(atoi(argv[1])); TextLines txtobj; txtobj.input(cin); quicksort(&txtobj, 0, txtobj.length()-1, CMP_FN(keycmp), SWAP_FN(lineswap)); txtobj.display(); return(0); }