Created
November 10, 2015 17:11
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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