Bubble sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.
Kata
Write a program that takes in list of integers and outputs the list in ascending size.
Now add the following functionality to your program. Each new functionality should be added one at a time, iterating on the initial program.
- Program takes in a parameter that determines if the output should be ascending or descending
- After each comparison, program outputs whether it resulted in a swap or not
- Program outputs how many swaps were done at the end of each complete pass
- Program outputs the total number of passes made to complete the sort
- Program outputs the total number of swaps done to compete the sort
If you complete that, refactor the program so that it can also take a multidimensional list of dimensions of rectangles (width, height) and output the list in order of area (it should also be able to perform the original functionality with a list of integers).
Is there anything that can be done to improve the performance of the sort?
When you added new functionality were you careful to simplify the code on each iteration?