Para
Para

Reputation: 2082

What kind of sorting algorithm is this?

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: 203

Answers (2)

sepp2k
sepp2k

Reputation: 370112

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

IVlad
IVlad

Reputation: 43477

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

Related Questions