% cd ~/cs21/ % mkdir week7 # if you have not already done so % cd week7 % cp ~newhall/public/cs21/week7/bubblesort.c . % cp ~newhall/public/cs21/week7/testinput . % ls
This algorithm is called Bubble Sort because values slowly bubble up to their correct position in the sorted array.
For example, if the starting content of the array are the following:
0 1 2 3 4 5 ------------------------------------- | 7 | 6 | 5 | 4 | 3 | 2 | -------------------------------------Then, after the first pass of the bubble sort algorithm the array contains:
0 1 2 3 4 5 -------------------------------------- | 6 | 5 | 4 | 3 | 2 | 7 | --------------------------------------
Try running and testing your implementation using an inputfile of input values and then re-directing a.out's stdin to read values from the inputfile. This is an easy way to test an interactive program so you don't have to enter them by hand each time. For example, my input file might contain:
9 10 8 33 55 88 99 77 2 6 -1Then when I run bubble sort I can re-direct its input from this file by using < :
% ./a.out < inputfile
You can see how long it takes to run bubble sort using the Unix time command:
% time ./a.out < inputfile