Skip to content

Instantly share code, notes, and snippets.

@sameerkumar18
Created November 28, 2015 06:32
Show Gist options
  • Save sameerkumar18/c3b20ad88fb6f630b5d9 to your computer and use it in GitHub Desktop.
Save sameerkumar18/c3b20ad88fb6f630b5d9 to your computer and use it in GitHub Desktop.
WAP to sort an array using Selection Sort
/*Programmed by www.fb.com/sameer18051998*/
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,n,loc,temp,min,a[30];
cout<<"Enter the number of elements:";
cin>>n;
cout<<"\nEnter the elements\n";
for(i=0;i<n;i++)
{
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<<"\nSELECTION Sorted list is as follows\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
getch();
}
/*Programmed by www.fb.com/sameer18051998*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment