If this is Bubble sort then what is this?
Do you see the placement of Swap()?
It's a kind of Selection Sort (as Maciej Hehl already said), but very ineffective. You swap way to many times. The effect is that you swap witch the minimum, but on the way there swap with each other that is smaller than the number you are looking at. That is unnecessary.
The first list is indeed selection sort. It is in essence the same as the algorithm on the link you've provided. But instead of finding the element that has the minimum value, and swapping it with arr[i]
once after the j
loop, the first code immediately swaps arr[i]
with any value it encounters which is smaller.
In both cases, at the end of the i
loop, arr[i]
will contain the smallest element in a within the range i+1..SIZE
.
There are two differences between the two algorithms: the code you show here performs more than one swap per iteration, and it shuffles the data that is not yet sorted (this is not really important, as they will eventually get sorted). So, basically it is less efficient than the code you've linked.
Maybe I am missing something subtle, but the first link (lorenzod8n.wordpress.com) shows a bubble sort; the second (cprogramminglanguage.net) a selection sort. It even says so in the text.
Edit: I missed/forgot something subtle: Bubble Sort exchanges adjacent entries; the algorithm in the first link doesn't. Hence, it's not Bubble Sort, though it does has Bubble Sort's excessive swapping behavior.