previous | index | next

Selection Sort Outer Loop

Since the outer loop ends by swapping the largest value with that in v[n], we can add:

    for (int n = SIZE-1; n > 0; n--) {
      indexOfLargest = 0;        

       ...                       // inner loop determines indexOfLargest

      temp = v[n];               // swap the highest position of the unsorted
      v[n] = v[indexOfLargest];  // part with the largest element
      v[indexOfLargest] = temp;
    }


previous | index | next