[Home]Bubble sort/C

HomePage | Bubble sort | Recent Changes | Preferences

Difference (from prior major revision) (no other diffs)

Removed: 1d0
A simple C bubblesort implementation for an array of integers:

Removed: 3,16d1

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
Last edited December 14, 2001 7:55 am by Lee Daniel Crocker (diff)
Search: