Contents

Precondition: the function accepts an unsorted array and integer size that is the size of the array.

Post condition: Sorted array

The function looks for the smallest number and moves it to the head of the array

void  SelectiveSort ( int  size, int array [] )
{
     int current  = 0;

                while (  current <  size )
               {
                    int smallest = current;
                    int walker = current +1;

                        while ( walker < size )
                        {
                        if ( array [walker] < array [smallest] )
                                smallest = walker;
                        walker ++;
                        }
                    exchange ( array, current,  smallest );
                    current ++;
               }
}


Contents