// File: array.C // // implementation of array class for testing sorting algorithms #include #include #include #include #include #include "array.h" // Constructor initializes array to random values // Array::Array(int n /* = DSIZE */, long seed /* = 0 */) { if (n <= 0) { cerr << "Bad array size" << endl ; exit(1) ; } // if no seed given for random number generator, use time // if (seed == 0) seed = (long) time(NULL) ; srand48(seed) ; arr = new DATA[n] ; if (arr == NULL) { cerr << "Out of memory in array constructor" << endl ; exit(1) ; } size = n ; Array::seed = seed ; for (int i = 0 ; i < size ; i++) { arr[i] = (DATA) drand48() ; } } void Array::print() { for (int i = 0 ; i < size ; i++) { cout << setw(12) << arr[i] ; if (i % 5 == 4) cout < arr[i+1]) return false ; } return true ; }