#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,temp,min;
cout<<"\nEnter the no. of elements you want:";
cin>>n;
int *a=new int[n]; //dynamically initialize array
cout<<"\nEnter the elements:\n";
for(int i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{
min=i;
for(int j=i+1;j<n;j++)
{
If(a[min]>a[j])
min=j;
}
temp=a[min];
a[min]=a[i];
a[i]=temp;
}
cout<<"\nSorted list of given integers is(in ascending order) :\n";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
getch();
}
By Gurpreet Singh, Department of Computer Science & Engineering, Amritsar College of Engineering & Technology
Saturday, 1 August 2015
Selection Sort Program
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment