Yeah, that was a typo. Bubble sort terminates when no swaps have been made.
The implementation given by the OP is insertion sort according to Knuth (and the implementation is almost line for line exactly the same as Knuth provides for what he calls "straight insertion sort". I agree that these two sorts are very similar, but they iterate (and terminate) differently. Also, from Bubble sort - Wikipedia :
So they're definitely different.Quote:
Bubble sort is asymptotically equivalent in running time to insertion sort in the worst case, but the two algorithms differ greatly in the number of swaps necessary. Experimental results such as those of Astrachan have also shown that insertion sort performs considerably better even on random lists. For these reasons many modern algorithm textbooks avoid using the bubble sort algorithm in favor of insertion sort.
For reference, Knuth's bubble sort is attached.
I'm probably being overly pedantic, but since the two are quite different and presented as two distinct algorithms in all my reference books (I've seen insertion sort presented as bubble sort in intro to algorithm books, though) I prefer to also refer to them as distinct (which they are) and call them what the reference books call them.
Edit: It seems like they have a very similar discussion on Rosetta Code Talk:Sorting algorithms/Bubble sort - Rosetta Code
@HelpMeC sorry for going off on a tangent. If your teacher wants to call it bubble sort then fine :P :) But, well, it's insertion sort. Maybe these days the two algorithms are called bubble sort for convenience