A sort routine which is easy to program is the bubble sort.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Order a Similar Paper HERE Order a Different Paper HERE

A sort routine which is easy to program is the bubble sort. The program simply scans all of the elements to be sorted repeatedly. On each pass, the program compares each element with the one next to it, and reorders the two, if they are in inverse order. For instance, to sort the following list:

6 7 3 1 4

Bubble sort starts by comparing 6 and 7. They are in the correct order, so it then compares 7 and 3. They are in inverse order, so bubble sort exchanges 7 and 3, and then compares 7 and 1. The numbers 7 and 1 are in reverse order, so bubble sort swaps them, and then compares 7 and 4. Once again, the order is incorrect, so it swaps 7 and 4. End of scan 1:

6 3 1 4 7

Scanning left to right again results in:

3 1 4 6 7

Scanning left to right again results in a correct ordering:

1 3 4 6 7

Write pseudocode for the bubble sort.