Skip to content

Instantly share code, notes, and snippets.

@shohan4556
Created October 26, 2014 01:35
Show Gist options
  • Save shohan4556/315e7d839a1e2af6bb58 to your computer and use it in GitHub Desktop.
Save shohan4556/315e7d839a1e2af6bb58 to your computer and use it in GitHub Desktop.
bubble sort algo
#include<stdio.h>
int main()
{
int n=0,i,j,k,ck,data[100];
while(scanf("%d",&n)!=EOF){
for(k=0;k<n;k++)
scanf("%d",&data[k]);
for(j=0;j<n-1;j++){
for(i=0;i<n;i++){
if(data[i]>data[i+1]){
ck=data[i];
data[i]=data[i+1];
data[i+1]=ck;
}
} // end child loop
}// end parent loop
for(i=0;i<n;i++)
printf("%d ",data[i]);
} // end while loop
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment