/** * runMergeSorts * * Creates a CensusData object and initializes it from the census * data file. Runs two sorts - one by population and one by city name - using * merge sort. * * @param fp File pointer to the census data file. */ void runMergeSorts(ifstream& fp) { timespec time1, time2; CensusData myCensusData; cout << endl << "**********MERGE SORT**********" << endl; myCensusData.initialize(fp); cout << endl << "Original Data" << endl; myCensusData.print(); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1); myCensusData.mergeSort(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.mergeSort(myCensusData.NAME); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2); cout << endl << "Sorted by NAME" << endl; printTime(myCensusData.getSize(), time1, time2); myCensusData.print(); }
/** * runInsertionSorts * * Creates a CensusData object and initializes it from the census * data file. Runs two sorts - one by population and one by city name - using * insertion sort. * * @param fp File pointer to the census data file. */ void runInsertionSorts(std::ifstream& fp) { timespec time1, time2; CensusData myCensusData; std::cout << std::endl << "**********INSERTION SORT**********" << std::endl; myCensusData.initialize(fp); std::cout << std::endl << "Original Data" << std::endl; myCensusData.print(); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1); myCensusData.insertionSort(myCensusData.POPULATION); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2); std::cout << std::endl << "Sorted by POPULATION" << std::endl; printTime(myCensusData.getSize(), time1, time2); myCensusData.print(); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1); myCensusData.insertionSort(myCensusData.NAME); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2); std::cout << std::endl << "Sorted by NAME" << std::endl; printTime(myCensusData.getSize(), time1, time2); myCensusData.print(); }