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;
}
}
}
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 =
Share
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.