The bubble sort algorithm is a simple sorting algorithm that can be implemented on any data which can be directly compared.
Consider you have the numbers 3 8 5 2 in that order as shown below
We first look at 3 and 8. 3 is smaller than 8 so we do not swap them. We then move to 8 and 5. 8 is larger than 5 so we swap them. Our numbers are now in this order
Then we look at 8 and 2. 8 is larger than 2 so we swap them. We have now hit the end of the list and after our first complete pass our list is now
Now in the second pass, 3 and 5 are not swapped, 5 and 2 are swapped, and then 5 and 8 are not swapped so we have
In the next pass, only 3 and 2 are swapped
Now when we do a pass, no swaps are made. The list is now sorted and our final list is