(Bubble sort) Write a sort function that uses the bubble-sort algorithm. The algorithm makes several passes through the array. On each pass, successive neighboring pairs are compared. If a pair is in decreasing order, its values are swapped; otherwise, the values remain unchanged. The technique is called a bubble sort or sinking sort because the smaller values gradually “bubble” their way to the top and the larger values sink to the bottom.
The algorithm can be described as follows:
bool changed = true ;do {changed = false ;for (int j = 0 ; j1 ; j++) if (1ist[j] > 1ist[j + 1 ]) { swap 1ist[j] with 1ist[j + 1 ]; changed = true ; }} while (changed);
Clearly, the list is in increasing order when the loop terminates. It is easy to show that the do loop executes at most listSize − 1 times.
Write a test program that reads in an array of ten double numbers, invokes the function, and displays the sorted numbers.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.