Skip to content

Commit

Permalink
Added bubble sort in c
Browse files Browse the repository at this point in the history
  • Loading branch information
Manish17292000 authored Oct 2, 2018
1 parent 90861fd commit 9ea67fc
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Bubble sort
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include<stdio.h>

/*
* @ar_size array size
* @ar array pointer
*/
void bubblesort(int ar_size, int * ar)
{
for(int i=0; i<ar_size; i++)
{
for(int j=0; j<ar_size-i-1; j++)
{
ar[j]=ar[j]^ar[j+1];
ar[j+1]=ar[j]^ar[j+1];
ar[j]=ar[j]^ar[j+1];
}

}
}
int main()
{
int ar[5]={5,4,3,2,1};
int ar_size=sizeof(ar)/sizeof(ar[0]);
bubblesort(ar_size, ar);
for(int i=0; i<ar_size; i++)
{
printf("%d\n", ar[i]);
}

}

0 comments on commit 9ea67fc

Please sign in to comment.