// File: mtest.cpp // Test the mergesort routine #include #include #include "sorts.H" using namespace std ; main(int argc, char *argv[]) { int size=0, seed=0 ; if (argc != 3) { cerr << "Usage: itest size seed" << endl ; exit(1) ; } size = atoi(argv[1]) ; seed = atoi(argv[2]) ; if (size <= 0 || seed <= 0) { cerr << "Bad size or seed" << endl ; exit(1) ; } // initialize array with random data // srand48(seed) ; double *A = new double[size] ; for (int i = 0 ; i < size ; i++) { A[i] = drand48() ; } MergeSort(A, 0, size-1) ; #ifndef NDEBUG for (int i = 0 ; i < size - 1 ; i++) { if (A[i] > A[i+1]) { cerr << "Error! array not sorted correctly" << endl ; } } for (int i = 0 ; i < size - 1 ; i++) { cout << A[i] << endl ; } #endif }