Here you will find out about the program for air pocket sort in C.
The bubble sort is a basic arranging calculation wherein every component is contrasted and neighbouring component and swapped if their position is off base. It is named as air pocket sort since same as like air pockets the lighter components come up and heavier components settle down.
Both most pessimistic scenario and normal case multifaceted nature are O (n2).
#include<stdio.h>
int main()
{
int a[50],n,i,j,temp;
printf("Enter the size of array: ");
scanf("%d",&n);
printf("Enter the array elements: ");
for(i=0;i<n;++i)
scanf("%d",&a[i]);
for(i=1;i<n;++i)
for(j=0;j<(n-i);++j)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
printf("\nArray after sorting: ");
for(i=0;i<n;++i)
printf("%d ",a[i]);
return 0;
}
Output
Enter the size of array: 4
Enter the array elements: 3 7 9 2
Array after sorting: 2 3 7 9