I have to time how long a bubble sort takes and print how long it took. In my program the time printed is always 0.00 seconds. Can anyone tell me what I'm doing wrong?
you can use clock_t then divide the result by CLOCKS_PER_SECOND
this will actually return a value if the time is under 1 second.. i've noticed that time_t will not return any values less than one second.
and if you use this method, do not use the difftime function
Also an interesting thing to do is use three accumulators one for pass count, one for comparison count, and one for swap count to give you an idea of how much work is being done using the ineficient bubble sort.
1 2 3 4 5 6 7
clock_t start, end;
start = clock();
///blah blah code here
end = clock();
timediff = (end - start) / (double)CLOCKS_PER_SEC;