On a side note, your bubble sort algorithm is doing some wasted work (will never have an effect). For example, consider this list of integers:
The first time through the outer loop (i = 0), the first element is compared to every element (including itself) and swapped if the other element is smaller.
It's trivial compared to all the comparisons being done, but comparing an element to itself will always fail the
test, so it's wasted effort.
But more importantly, what do we know about element 0 at this point? It's the smallest value in the list and therefore will never be swapped again. Yet it will continue to be compared each time through the loop.
So on the first loop we know that you only need to compare element 0 to elements 1, 2, and 3. On the second loop, you must compare element 1 to only 2 and 3. Can you generalize this
pattern?