// File: makesortedfile.C // // Use Quicksort to sort an array and store output in a binary file. #include #include #include #include "array.h" #include "sorts.h" main(int argc, char *argv[]) { int size=0, seed=0 ; if (argc != 4) { cerr << "Usage: makesortedfile size seed fname" << endl ; exit(1) ; } size = atoi(argv[1]) ; seed = atoi(argv[2]) ; if (size <= 0 || seed <= 0) { cerr << "Bad size or seed" << endl ; exit(1) ; } Array A(size, seed) ; QuickSort(A) ; ofstream ofile ; ofile.open(argv[3]) ; if (ofile == NULL) { cerr << "Could not open file " << argv[3] << " for output!" << endl ; exit(1) ; } ofile.write((char *) A.arr, sizeof(DATA)*A.length()) ; ofile.close() ; }