Bubble Sort (Ascending)
- In this algorithm we compare the first two adjacent items in the list. If the first item is larger than the item next to it, we swap them, else we do nothing.
- This process (step1) is repeated until we have reached the end of the list. At this point, the largest item is at the end of the list, we say it was “bubbled” up the list.
- Repeat step 1 and 2 for items 1 .. n-1, then 1 .. n-2 and so on until we reach 1..2
It seems difficult to understand but we can observe the algorithm in action in the following flowchart:

You can download the file here:
https://drive.google.com/file/d/1RvZ-dBvbHf0icL083d7vSnnce3_XDyyj/
Demonstration
See : https://youtu.be/KgqM6sC5Q4M
Exercise
Implement the algorithm in c with the following modifications:
- The array stores double data
- Print the array to the screen as a comma separated list before sorting.
- Print the array to the screen as a comma separated list after sorting.
Challenge
Create a function with the following functions declaration which will sort any double array using bubble sort:
void bubbleSort(double array[], int sizeOfArray);
© 2020 Vedesh Kungebeharry. All rights reserved.