コード例 #1
0
/**
 * runQuickSorts
 *
 * Creates a CensusData object and initializes it from the census
 * data file. Runs two sorts - one by population and one by city name - using
 * quicksort.
 *
 * @param fp   File pointer to the census data file.
 */
void runQuickSorts(ifstream& fp) {
   timespec time1, time2;
   CensusData myCensusData;
   
   cout << endl << "**********QUICK SORT**********" << endl;
   myCensusData.initialize(fp);
   cout << endl << "Original Data" << endl;
   myCensusData.print();
   
   clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
   myCensusData.quickSort(myCensusData.POPULATION);
   clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
   cout  << endl << "Sorted by POPULATION" << endl;
   printTime(myCensusData.getSize(), time1, time2);
   myCensusData.print();
   
   clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
   myCensusData.quickSort(myCensusData.NAME);
   clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
   cout << endl << "Sorted by NAME" << endl;
   printTime(myCensusData.getSize(), time1, time2);
   myCensusData.print();
}