forked from OSDG-IIITH/hactoberfestcollection
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ea67fc
commit 4e3e84d
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
|
||
} |