vector<double> sortingPerf(int method, int n, int m = 1) { assert(n > 0); vector<double> ans(n, 0.0); for (int i = 1; i <= n; i++) ans[i] = sortTime(method, i, m); return ans; }
//hall of fame mode void hof(){ char ch; int i, x; char *result; int n=0, m = 0; FILE *fptr; //create file pointer fptr = fopen("HallofFame.txt", "r"); //open HallofFame.txt while ( ( ch = fgetc( fptr ) ) != EOF ){ //determine the number of lines in the file if(ch==10)n++; //we need that to know how big to make the array later } //returns n which is the number of lines rewind(fptr); struct data entry[n]; //create a data array to hold the records from the HallofFame.txt file for(i=0; i<n; i++){ //loop n to read all records from the file char info[50]; fscanf(fptr, "%s", &info); //read a line from the file result = strtok(info, ","); strcpy(entry[i].name,result); //store name result = strtok(NULL, ","); entry[i].diff=atoi(result); //store level result = strtok(NULL, ","); entry[i].moves=atoi(result); //store steps result = strtok(NULL, ","); entry[i].time=atoi(result); //store time from the file } fclose(fptr); //close the file after reading all records ch = 'p'; while(ch!=27){ if(ch==49)sortName(entry, n, 1); //call the required sort method based on user's choice if(ch==50)sortDiff(entry, n, 1); if(ch==51)sortMoves(entry, n, 1); if(ch==52)sortTime(entry, n, 1); if(ch==53)sortName(entry, n, 0); if(ch==54)sortDiff(entry, n, 0); if(ch==55)sortMoves(entry, n, 0); if(ch==56)sortTime(entry, n, 0); system("cls"); printf("\nPress 1 to sort by Name (Ascending)\nPress 2 to sort by Level (Ascending)\nPress 3 to sort by Steps (Ascending)\nPress 4 to sort by Time (Ascending)"); printf("\nPress 5 to sort by Name (Descending)\nPress 6 to sort by Level (Descending)\nPress 7 to sort by Steps (Descending)\nPress 8 to sort by Time (Descending)"); printf("\nPress ESC to exit\n"); ch = getch(); } return; }
void sortsPerformanceHybridVsMergeVsMergeBu() { int startVal = 100; int endVal = pow(startVal, 4); int numRepeat = 1; for (int i = startVal; i <= endVal; i *= 10) { double mergeTime = sortTime(0, i, numRepeat); double hybridTime = sortTime(2, i, numRepeat); double mergeBuTime = sortTime(3, i, numRepeat); cout << "n: " << i << " "; cout << "merge : " << mergeTime << " | "; cout << "hybrid : " << hybridTime << " | "; cout << "mergeBu : " << mergeBuTime << " "; cout << " >> "; cout << getWinner(mergeTime, mergeBuTime, hybridTime); cout << endl; } }
double timeRandomInput (char *compareType,int N,int T) { double total = 0.0; double a[N]; for (int i=0; i<T; i++) { for(int j=0; j<N; j++){ a[j] = random(); } // a[0] = 3.4; // a[1] = 5.0; // a[2] = 4.1; total += sortTime(compareType, a, N); } return total; }