Reputation: 2082
int aux;
for(int i=0;i<array.Count()-1;i++)
{
for(int j=i+1;j<array.Count();j++)
{
if(array[i] > array[j])
{
aux = array[j];
array[j] = array[i];
array[i] = aux;
}
}
}
Upvotes: 1
Views: 205
Reputation: 370435
This is almost selection sort, except that you don't swap the minimum remaining element with the current element, but you swap every remaining element that's smaller than the current with the current element until the current element is the minimum.
Upvotes: 1
Reputation: 43517
This is a dumbed down selection sort. Instead of swapping array[i]
with the minimum element after it, you just swap it with each smaller element. Eventually the correct element will obviously end up in the right position, and you do write less code.
This is a lot less efficient because more swaps are performed, but it's basically selection sort.
Upvotes: 8