Skip to content

Instantly share code, notes, and snippets.

@nalin-adh
Created November 10, 2015 17:11
Show Gist options
  • Save nalin-adh/26f2a5c4fcd5533aead3 to your computer and use it in GitHub Desktop.
Save nalin-adh/26f2a5c4fcd5533aead3 to your computer and use it in GitHub Desktop.
A C++ program 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]<<" ";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment