Created
October 9, 2017 20:13
-
-
Save rahuladream/6da3944e02ceb2991adfdb58439feb8c to your computer and use it in GitHub Desktop.
Selection Sort
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
#include<iostream> | |
using namespace std; | |
int main() | |
{ | |
int i,j,n,loc,temp,min,a[30]; | |
cout<<"Enter the number of elements:"; | |
cin>>n; | |
cout<<"Enter the element"; | |
while(cin>>a[i]) | |
for(i=0;i<n-1;i++) | |
{ | |
min=a[i]; | |
loc=i; | |
for(j=i+1;j<n;j++) | |
{ | |
if(min>a[j]) | |
{ | |
min=a[j]; | |
loc=j; | |
} | |
} | |
temp=a[i]; | |
a[i]=a[loc]; | |
a[loc]=temp; | |
} | |
cout<<"\nSorted list is as follows\n"; | |
for(i=0;i<n;i++) | |
{ | |
cout<<a[i]<<" "; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment