Resources » Articles/Knowledge Sharing » Computer & Technology

Selection/ Exchange Sort Program in C++


Posted Date: 15-Jan-2009  Last Updated:   Category: Computer & Technology    
Author: Member Level: Silver    Points: 2


Read it for Selection/ Exchange Sort Program in C++



/* A Program to exchange sort in array */

#include
#include
void SelSort(int [],int);
void main()
{
int AR[20],n;
clrscr();
cout<<"HOW MANY ELEMENT DO U WANT TO CREATE ARRAY WITH?";
cin>>n;
cout<<"\n Enter the array element....\n";
for (int i=0;i{ cin>>AR[i]; }
SelSort(AR,n);
cout<<"\n\nThe sorted array is as shown below...\n";
for(i=0; icout<cout<}
void selsort (int AR[],int size)
{ int small, pos, tmp ;
for(int i=0;i { small=AR[i];
pos=i;
for(int j=i+1;j { if(AR[j] { small=AR[j];
pos=j;
}
}
tmp = AR[i];
AR[i] = AR[pos];
AR[pos] = tmp;
cout<<"\n Array after pass - "< for(j=0;j cout< }
}


//THE OUTPUT OF ABOVE PROGRAM IS AS FOLLWS: //

HOW MANY ELEMENT DO U WANT TO CREATE ARRAY WITH?6
Enter the array element....
6
8
10
12
5
8

Array after pass - 1- is :
5 8 10 12 6 8
Array after pass - 2- is :
5 6 10 12 8 8
Array after pass - 3- is :
5 6 8 12 10 8
Array after pass - 4- is :
5 6 8 8 10 12
Array after pass - 5- is :
5 6 8 8 10 12
Array after pass - 6- is :
5 6 8 8 10 12

The sorted array is as shown below...
5 6 8 8 10 12


Did you like this resource? Share it with your friends and show your love!




Responses to "Selection/ Exchange Sort Program in C++"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Awards & Gifts
    Active Members
    TodayLast 7 Daysmore...

    Online Members

    Vellamji
    More...
    ISC Technologies, Kochi - India. Copyright © All Rights Reserved.