#include "main.h" int main(void) { long test; #ifdef macintosh InitMacintosh(); #endif int i; cout << "Initializing...." << endl; gIntSize = sizeof(int); cout << "Using " << gIntSize << " byte integers." << endl; maxInt = (pow(2,(gIntSize*8-1))-1); test = (pow(2,(gIntSize*8-1))-1); //these will be different if sizeof failed. if (test != maxInt) { cout << "Error: Integer size invalid" << endl; myExit(0); } gDone = 0; while (gDone != 1) { cout << "Which sorting method would you like to use: " << endl; cout << "1: Bubble sort " << endl << "2: Quick sort" << endl << "3: Binary Tree" << endl << "4: Hashtable" << endl << "5: Quit!" << endl; cin >> i; switch (i) { case (1) : createArray(); doBubbleSort(); break; case (2) : createArray(); doQuickSort(); break; case (3) : createArray(); doTreeSort(); break; case (4) : doHashtable(); break; case (5) : gDone = 1; break; default : cout << "Invalid option" << endl; break; } } cout << "Bye!" << endl; } void createArray(void) { register int i; long max; #ifndef macintosh time_t t; #else unsigned long randSeed; #endif #ifdef macintosh GetDateTime(&randSeed); srand(randSeed); #else srand(time(&t)); #endif cout << "Please enter the maximum value for the numbers: "; cin >> max; cout << endl; if (max > maxInt) { cout << "Error: Number entered is larger than MAXINT" << endl; myExit(0); } for (i = 0; i < 50; i++) { #ifdef macintosh numbers[i] = abs(Random() % max); #else numbers[i] = rand() % max; #endif } } void myExit(int retval) { #ifdef macintosh ExitToShell(); #else exit(retval); #endif }