#include <stdio.h>
#define MAX 10

void bubbleSort(int array[MAX])
{
  for (int maxIndex = MAX; maxIndex > 0; maxIndex--)
  {
    for (int prevIndex = 0, currentIndex = 1; currentIndex < maxIndex; prevIndex++, currentIndex++)
    {
      if (array[prevIndex] > array[currentIndex])
      {
        int temporary = array[prevIndex];
        array[prevIndex] = array[currentIndex];
        array[currentIndex] = temporary;
      }
    }
  }
}

void show(int index, int array[MAX])
{
    if (index != MAX)
    {
        printf("%d ", array[index]);
        show(index + 1, array);
    }
}

void main()
{
    int array[] = {3, 10, 4, 6, 8, 9, 7, 2, 1, 5};
    // int array[] = {1, 2, 3, 4, 5, 9, 7, 6, 8, 10};
    // int array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    // int array[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};

    printf("Array\nBefore: ");
    show(0, array);

    bubbleSort(array);

    printf("\nAfter: ");
    show(0, array);
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: