[Home]Bubble sort/C

HomePage | Bubble sort | Recent Changes | Preferences

Showing revision 2
A simple C bubblesort implementation for an array of integers:

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;
      }
}


HomePage | Bubble sort | Recent Changes | Preferences
This page is read-only | View other revisions | View current revision
Edited October 30, 2001 6:07 am by 66.161.187.xxx (diff)
Search: