void RunStringSort(){ //building a list of valid characters for random strings. alphabetical + spaces. Vector<char> chars; for(int i = 65; i < 91; i++){ chars.add((char)i); } for(int i = 97; i < 123; i++){ chars.add((char)i); } chars.add(' '); // populating a vector with some random strings Vector<string> teststrings; for(int i = 0; i < 40; i++){ teststrings.add(RandomString(chars,RandomInteger(3,10))); } // running the vector through the sort algorithm. cout << "Testing our CombSort on a vector of strings..." << endl << endl; cout << "Here is the unsorted vector of strings:" << endl << endl; PrintVectorString(teststrings); CombSort(teststrings,StringCmp); cout << "Here is the sorted version." << endl << endl; PrintVectorString(teststrings); }
void RunIntSort(){ Vector<int> randarr = RandomArray(500,0,500); //unused code for testing an already-sorted list Vector<int> orderedarr; for(int i = 0; i < 10000; i++){ orderedarr.add(i); } cout << "Testing our CombSort on a vector of random integers..." << endl << endl; cout << "Here is the unsorted vector of integers:" << endl << endl; PrintVectorInt(randarr); CombSort(randarr); cout << "Here is the sorted version" << endl << endl; PrintVectorInt(randarr); }
void RunSetIntSort(){ // Populating a vector with randomized sets. Vector<Set<int> > testsets; for(int i = 0; i < 40; i++){ Set<int> newset; Vector<int> nums = RandomArray(RandomInteger(4,12),0,50); for(int i = 0; i < nums.size(); i++){ newset.add(nums[i]); } testsets.add(newset); } // Putting the vector of sets through the sort! cout << "Testing our CombSort on a vector of sets of integers." << endl << endl; cout << "Here is the unsorted vector of sets:" << endl << endl; PrintVectorSetInt(testsets); CombSort(testsets,SetIntCmp); cout << "Here is the sorted version." << endl << endl; PrintVectorSetInt(testsets); }
int main(void) { datatype data[N]; datatype temp[N]; int i; srand((unsigned int)time(NULL)); for(i = 0; i < N; i++) { data[i] = rand() % (NUM_LIMITS + 1); } Print(data, N); Copy(data, temp, N); printf("InsertionSort: \n"); InsertionSort(data, N); Print(data, N); Copy(temp, data, N); printf("BinaryInsertionSort:\n"); BinaryInsertionSort(data, N); Print(data, N); Copy(temp, data, N); printf("ShellSort:\n"); ShellSort(data, N); Print(data, N); Copy(temp, data, N); printf("SelectionSort:\n"); SelectionSort(data, N); Print(data, N); Copy(temp, data, N); printf("BubbleSort:\n"); BubbleSort(data, N); Print(data, N); Copy(temp, data, N); printf("QuickSort:\n"); QuickSort(data, 0, N-1); Print(data, N); Copy(temp, data, N); printf("MergeSort:\n"); MergeSort(data, 0, N-1); Print(data, N); Copy(temp, data, N); printf("HeapSort:\n"); HeapSort(data, N); Print(data, N); Copy(temp, data, N); printf("PigeonholeSort:\n"); PigeonholeSort(data, N); Print(data, N); Copy(temp, data, N); printf("BucketSort:\n"); BucketSort(data, N, NUM_LIMITS); Print(data, N); Copy(temp, data, N); printf("CocktailSort:\n"); CocktailSort(data, N); Print(data, N); Copy(temp, data, N); printf("GnomeSort:\n"); GnomeSort(data, N); Print(data, N); Copy(temp, data, N); printf("OddEvenSort:\n"); OddEvenSort(data, N); Print(data, N); Copy(temp, data, N); printf("PatienceSort:\n"); PatienceSort(data, N); Print(data, N); Copy(temp, data, N); printf("BeadSort:\n"); BeadSort(data, N); Print(data, N); Copy(temp, data, N); printf("CombSort:\n"); CombSort(data, N); Print(data, N); Copy(temp, data, N); printf("BogoSort(Do you believe fortune?):\n"); // BogoSort(data, N); // Print(data, N); return 0; }