WAP to sort n numbers in descending order using selection sort.


#include<iostream>
#include<conio.h>

using namespace std;

void display(int b[]);

int main()
{
int a[10]={2,3,6,8,9,0,1,4,7,2},large,index;

cout<<"Numbers before SELECTION SORT\n";

display(a);

for(int i=9;i>0;i--)
{
large=a[9];
index=0;

for(int j=1;j<=i;j++)
{
if(a[j]>large)
{
large=a[j];
index=j;
}
a[index]=a[i];
a[i]=large;
}

}

cout<<"\nNumbers after SELECTION SORT\n";

display(a);

getch();
return(0);
}

void display(int b[])
{
for(int i=0;i<10;i++)
{
cout<<b[i]<<" ";
}
}

No comments:

Post a Comment