// File: qsmain3.cpp // // Test of templated quicksort #include #include #include #include #include #include "quicksort.H" using namespace std ; main() { int *A, i, n=50 ; srand48(time(NULL)) ; A = new int[n] ; if (A == NULL) abort() ; cout << "\nOriginal Array: " << endl ; for (i = 0 ; i < n ; i++) { A[i] = lrand48() ; cout << setw(12) << A[i] << " " ; if (i % 5 == 4) cout << endl ; } QuickSort(A,n) ; cout << "\nSorted Array: " << endl ; for (i = 0 ; i < n ; i++) { cout << setw(12) << A[i] << " " ; if (i % 5 == 4) cout << endl ; } // Do it again with a floating point array double *B = new double[n] ; if (B == NULL) abort() ; cout << "\nOriginal Array: " << endl ; for (i = 0 ; i < n ; i++) { B[i] = drand48() ; cout << setw(12) << B[i] << " " ; if (i % 5 == 4) cout << endl ; } QuickSort(B,n) ; cout << "\nSorted Array: " << endl ; for (i = 0 ; i < n ; i++) { cout << setw(12) << B[i] << " " ; if (i % 5 == 4) cout << endl ; } // One more time with strings string C[10] ; C[0] = "And so too, all the added moodiness which always afterwards," ; C[1] = "to the very day of sailing in the Pequod" ; C[2] = "on the present voyage" ; C[3] = "sat brooding on his brow." ; C[4] = "Nor is it so very unlikely," ; C[5] = "that far from distrusting his fitness for another whaling voyage," ; C[6] = "on account of such dark symptoms," ; C[7] = "calculating people of that prudent isle" ; C[8] = "were inclined to harbor the conceit," ; C[9] = "that for those very reasons he was all the better qualified" ; cout << "\nOriginal Array: " << endl ; for (i = 0 ; i < 10 ; i++) { cout << "C[" << i << "]=\"" << C[i] << "\"\n" ; } QuickSort(C,10) ; cout << "\nSorted Array: " << endl ; for (i = 0 ; i < 10 ; i++) { cout << "C[" << i << "]=\"" << C[i] << "\"\n" ; } }