next up previous contents index Search
Next: 0.3.8 Bubble Sort Up: 0.3.7 Selection Sort Previous: 0.3.7.1 Analysis

0.3.7.2 Source Code

A C implementation of the Selection Sort which finds the lowest value in the remaining data set is given above.


void selectionsort(int *array, int size) {
  int i, j, lowindex;

  for (i = 0; i < size - 1; i++) {
    lowindex = i;
    for (j = size - 1; j > i; j--)
      if (array[j] < array[lowindex]) lowindex = j;
    swapi (\&array[i], \&array[lowindex]);
  }
}

Scott Gasch
1999-07-09