Skip to content

Instantly share code, notes, and snippets.

@rohit-nsit08
Created September 2, 2011 15:15
Show Gist options
  • Select an option

  • Save rohit-nsit08/1188885 to your computer and use it in GitHub Desktop.

Select an option

Save rohit-nsit08/1188885 to your computer and use it in GitHub Desktop.
simple bubble sort
#include<stdio.h>
int main()
{
int arr[5]={5,4,3,2,1};
int n = sizeof(arr)/sizeof(int);
int i,j,t;
for(i=1;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(arr[j]>arr[j+1])
{
t = arr[j];
arr[j] = arr[j+1];
arr[j+1] = t;
}
}
}
for(i=0;i<n;i++)
printf("%d ",arr[i]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment