/* Main function loops through all of the data sets, loads each one into a vector, then runs that data set on both Insertion Sort and Bubble Sort, then outputs algorithm step counts and runtimes for both Insertion Sort and Bubble Sort, then repeats with the next data set until the "content" vector is finished */ int main(){ std::string filename; filename = "dus-"; std::string fileExtension; fileExtension = "_SORTED.txt"; std::vector<std::string> content = {"2","4","6","8","10","12","16","20","24"}; int fileNum = content.size(); std::cout<<"File Name__________________Algorithm_______________Number of Steps_____________Duration\n\n"; for(int i=0; i<fileNum; i++){ insertionCount=0; bubbleCount=0; std::string file = filename+content[i]+fileExtension; std::vector<int> data; read_file(file, data); std::vector<int> data_copy = data; std::vector<int> data_copy_copy = data; beforeInsertion = clock(); Insertion_Sort(data_copy); afterInsertion = clock(); insertionTime = double(afterInsertion-beforeInsertion)/CLOCKS_PER_SEC; std::cout<<file<<" Insertion Sort "<<insertionCount<<" "<<insertionTime<<" Seconds\n"; beforeBubble = clock(); Bubble_Sort(data_copy_copy); afterBubble = clock(); bubbleTime = double(afterBubble-beforeBubble)/CLOCKS_PER_SEC; std::cout<<file<<" Bubble Sort "<<bubbleCount<<" "<<bubbleTime<<" Seconds\n"; } std::cout<<"\n"; }
void bubble() { extern int *input; int *copy_input[LOOP_COUNT]; int i, j; // Time check variable double time; BOOL err; for (i = 0; i < LOOP_COUNT; i++){ copy_input[i] = (int *) malloc(sizeof(int) * DATA_SIZE); for (j = 0; j < DATA_SIZE; j++) { // copy data copy_input[i][j] = input[j]; } } CHECK_TIME_START; for (i = 0; i < LOOP_COUNT; i++) { Bubble_Sort(copy_input[i]); // if(x%(LOOP_COUNT/10) == 0) printf("*"); // printf("Selecting Result --> input[%d] : %d\n", result, input[result]); } CHECK_TIME_END(time, err); // // data output check // for (i = 0; i < DATA_SIZE; i++) { // if(i%(DATA_SIZE/10) == 0) printf("%d : %d, ", i, copy_input[i]); // } // printf(" Calc Time = %.0fus\n", time/LOOP_COUNT); printf("%.0f\n", time / LOOP_COUNT); }
void Test_Bubble_Sort() { int len = ARRARY_SIZE; int *nArrary = new int[len] ; assert(GetRandArray(nArrary, len)); DumpArray(nArrary, len); int interval = GetTickCount(); Bubble_Sort(nArrary, len); interval = GetTickCount() - interval; printf("Bubble_Sort with InsertionSort: Consume %d millisecond to sort %d items \r\n", interval, len); DumpArray(nArrary, len); delete nArrary; nArrary = NULL; }
int main() { int A[7]={89,45,68,90,29,34,17}; Bubble_Sort(A,7); return 0; }