Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Selection sort
Index -> Programming, C++ -> C++ Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rickdragon




PostPosted: Tue Jan 13, 2004 2:21 pm   Post subject: Selection sort

#include<iostream.h>
#include<conio.h>
void main()
{
int i,n,k,j,a[100],min,loc,temp;
clrscr();
cout<<"Enter the size of an array : ";
cin>>n;
clrscr();
cout<<"Enter the element of the array : "<<endl;
for(k=1;k<=n;k++)
cin>>a[k];
for(k=1;k<=n;k++)
{
min = a[k];
loc = k;
for(j=k+1;j<=n;j++)
{
if(min > a[j])
{
min = a[j];
loc = j;
}
}
temp = a[k];
a[k] = a[loc];
a[loc] = temp;
}
clrscr();
cout<<"The sorted elements of an array are : "<<endl;
for(k=1;k<=n;k++)
cout<<a[k]<<endl;
getch();
}
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, C++ -> C++ Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: