I need some help, could someone explain the code below
I know it is implementing a select sort, but I can see why 2 for loops are needed. Please explain.
Code:
void selectionSort(int arr[], int len){
int i;
int j;
int temp;
int pos_greatest;
for( i = len - 1; i > 0; i--){
pos_greatest = 0;
for(j = 0; j <= i; j++){
if( arr[j] > arr[pos_greatest]){
pos_greatest = j;
}//end if
}//end inner for loop
temp = arr[i];
arr[i] = arr[pos_greatest];
arr[pos_greatest] = temp;
}//end outer for loop
}//end selection sort