# Bubble Sorting Algorithm

Bubble Sorting Algorithm

#include <stdio.h>
#include <ctype.h>

void bubblesort(int *, const int, char);
void swap(int *, int *);

int main()
{
const int i = 10;
int a[11];
char b;
printf("Enter a number:
");
int c;
for (c=0;c<10;c++)
{
printf("%d: ",c+1);
scanf("%d",&a[c]);
}

printf("Data Items in Original Order:

");

for (c=0;c<i;c++)
{
printf("%d
",a[c]);
}

printf("Which order would you like?: ");
scanf("%s",&b);
if (b=='a')
{
bubblesort(a,i,'a');
printf("Data Items in Ascending Order:
");
for (c=0;c<i;c++)
{
printf("%d
",a[c]);
}
}
else if(b=='d')
{
bubblesort(a,i,'d');
printf("Data Items in Decending Order:
");
for (c=0;c<i;c++)
{
printf("%d
",a[c]);
}
}
printf("Thank you for using BubbleSort");
return 0;
}

void bubblesort(int * array, const int size, char order)
{

order=tolower(order);
for (int pass=1;pass<size;pass++)
{
for (int j=0;j<size-1;j++)
{
if (order=='a')
{
if (array[j]>array[j+1])
{
printf("%d : ",array[j]);
printf("%d
",array[j+1]);
swap(&array[j],&array[j+1]);
}
}
if (order=='d')
{
if (array[j]<array[j+1])
{
printf("%d : ",array[j]);
printf("%d
",array[j+1]);
swap(&array[j],&array[j+1]);
}
}
}
}
}

void swap(int *e1, int *e2)
{
int swap=*e1;
*e1=*e2;
*e2=swap;
}