Skip to content

Commit

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

/*
* @ar_size array size
* @ar array pointer
*/
void selectionsort(int ar_size, int * ar)
{
for(int j=0; j<ar_size; j++)
{
int temp;
int imin=j;
for(int i=j+1; i=ar_size; i++)
{
if(ar[i]<ar[imin])
{
imin=i;
}
}

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

}

0 comments on commit 4e3e84d

Please sign in to comment.