Bubblesort

Question
Write an implementation of bubblesort (in your language of choice).
 * 1) What is the time complexity?
 * 2) Is your implementation a stable sort?
 * 3) Can your implementation be optimized? If so, how?

Answer
(Paper, not compiler tested)


 * 1) We need to iterate over the entire array for a single pass, and n such passes may be needed, so the time complexity is n^2, where n is size of the array.
 * Yes, this bubblesort will preserve the order of equal elements, so it is stable.
 * 1) Yes. The nth pass puts the nth largest number into it's final resting position. So after n passes, we don't need to consider the last n elements in the array, as they are already in their final location:

What's missing?
After running the code through a compiler, did you find any mistakes?

The return value is missing: