Pure Programmer
Blue Matrix


Cluster Map

Project: Bubble Sort

The [[Bubble sort]] is perhaps the easiest sort to implement. Write a function that takes a list of integers and sorts the list, in place, using a bubble sort. Test the function by creating a random list of integers, print the random list, sort the list, then print out the sorted list. Accept the number of integers to put in the list and the maximum integer to randomly generate on the command line. What is the worst case performance of the Bubble sort?

Output
$ python3 BubbleSort.py 10 10 Random List [2, 2, 4, 3, 8, 6, 5, 6, 0, 5] Sorted List [0, 2, 2, 3, 4, 5, 5, 6, 6, 8] $ python3 BubbleSort.py 20 100 Random List [76, 79, 98, 60, 66, 9, 65, 98, 19, 15, 9, 19, 22, 48, 46, 24, 5, 10, 28, 48] Sorted List [5, 9, 9, 10, 15, 19, 19, 22, 24, 28, 46, 48, 48, 60, 65, 66, 76, 79, 98, 98]

Solution