Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //================================================================================
- // Name : practical4.cpp
- // Author :
- // Version : 1.0
- // Description : practical 4 test program to utilise sort algorithms
- //================================================================================
- #include <string> // used to access string type
- #include <cctype>
- #include <ctime> // used to access clock_t and clock()
- #include "Array.h"
- #include "Sorter.h"
- using namespace std;
- // Test relative sort performances when sorting same
- // random and sorted number sequence.
- void testPerformance(int size) {
- clock_t start, start1, finish, finish1;
- // Create a sorter of specified size for one sort
- // then fill sorter with random numbers
- // Create sorters for other sorts and initialise with the
- // random numbers in the first sorter.
- // Consider what Sorter methods/constructors should be used
- // time sort of random data
- // create a Sorter for each sort algorithm ensuring each
- // contain the same random numbers. Use of Sorter copy
- // constructor is one way to ensure this!!
- Sorter<int> qsorter(size);
- qsorter.fillRandom(size);
- Sorter<int> isorter(qsorter);
- Sorter<int> msorter(qsorter);
- Sorter<int> ssorter(qsorter);
- //Quick Sort
- start = clock();
- qsorter.quickSort();
- finish = clock();
- start1 = clock();
- qsorter.quickSort();
- finish1 = clock();
- cout << "Quick Sort " << size << " Random/Sorted = " << (finish - start) << "/" << (finish1 - start1) << endl;
- //Selection Sort
- start = clock();
- ssorter.selectionSort();
- finish = clock();
- start1 = clock();
- ssorter.selectionSort();
- finish1 = clock();
- cout << "Selection Sort " << size << " Random/Sorted = " << (finish - start) << "/" << (finish1 - start1) << endl;
- //Insertion Sort
- start = clock();
- isorter.insertionSort();
- finish = clock();
- start1 = clock();
- isorter.insertionSort();
- finish1 = clock();
- cout << "Insertion Sort " << size << " Random/Sorted = " << (finish - start) << "/" << (finish1 - start1) << endl;
- //Merge Sort
- start = clock();
- msorter.mergeSort();
- finish = clock();
- start1 = clock();
- msorter.mergeSort();
- finish1 = clock();
- cout << "Merge Sort " << size << " Random/Sorted = " << (finish - start) << "/" << (finish1 - start1) << endl;
- }
- // Determine the most frequent word in the supplied text file 'words.txt'
- // print the word and its frequency
- void wordFrequency() {
- Sorter<string> words;
- // complete method by loading content of test.txt into 'words' sorter
- // defined above (use the sorter loadFile method). Sort the content by
- // (calling a sorter sort methd (any will do), then extract the sorted
- // array from the sorter (use the sorter getElements() method). Finally
- // loop through the sorted array and determine the most frequently occuring word
- // print the word and the number of occurences
- }
- // Main method.
- int main() {
- //initialise the random number generator
- srand((unsigned)time(NULL));
- testPerformance(500000);
- // q1 testPerformance
- // create a loop to call with values e.g. 10000,15000,2000
- // call the word frequency method to solve q2
- // ---------------------------------------------------
- cout << endl << "Press enter to quit";
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement