Bubble sort.c

From Algorithmist
Jump to: navigation, search

This is an implementation of Bubble sort in C. This algorithm is iterative.

void bubbleSort(int numbers[], int array_size)
{
  int i, j, temp;
 
  for (i = (array_size - 1); i > 0; i--)
  {
    for (j = 1; j <= i; j++)
    {
      if (numbers[j-1] > numbers[j])
      {
        temp = numbers[j-1];
        numbers[j-1] = numbers[j];
        numbers[j] = temp;
      }
    }
  }
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox