void bubbleSort(int *array, int length) { int i, j; for(i = length - 1; i > 0; i--) for(j = 0; j < i; j++) if(array[j] > array[j+1]) /* compare neighboring elements */ { int temp = array[j]; /* swap array[j] and array[j+1] */ array[j] = array[j+1]; array[j+1] = temp; } }
|