previous | index | next

Selection Sort Inner Loop

The inner loop looks for a value larger than that in v[indexOfLargest].

If it finds one, it updates indexOfLargest:

    for (int n = SIZE-1; n > 0; n--) {
      indexOfLargest = 0;
        for (int i = 1; i <= n; i++) {
          if ( v[i] > v[indexOfLargest] ) {
            indexOfLargest = i;
          }
        }
      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