I am just learning the selection sort algorithm and I cannot seem to understand how this selection sort works. Its supposed to take the largest index and sort it. Any help would be appreciated!
int findLargestIndex( int a[], int size )
{
int index = 0;
for ( int i = 0; i < size; i++ )
{
if ( a[i] > a[index] )
{
index = i;
}
}
return index;
}
void swap( int &a, int &b )
{
int tmp = a;
a = b;
b = tmp;
}
void sortMaxIndex( int a[], int size )
{
int last = size - 1;
for ( int i = 0; i < size; i++ )
{
for ( int j = 0; j <= last; j++ )
{
int max_index = findLargestIndex(a, size);
swap( a[last], a[max_index] );
}
}
}