mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Create rankSort.cpp
rank sort added
This commit is contained in:
parent
6376bf46af
commit
5f2706527a
43
sorting/rankSort.cpp
Normal file
43
sorting/rankSort.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
void rankSort(int arr[],int n){
|
||||
int rank[n];
|
||||
int out[n];
|
||||
|
||||
for(int i=0;i<n;i++){
|
||||
rank[i] = 0;
|
||||
}
|
||||
|
||||
for(int i=0;i<n;i++){
|
||||
for(int j=0;j<n;j++){
|
||||
if(arr[i]>arr[j])
|
||||
rank[i]++;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0;i<n;i++){
|
||||
out[rank[i]] = arr[i];
|
||||
}
|
||||
|
||||
cout<<"\nSorted Array : \n";
|
||||
for(int i=0;i<n;i++){
|
||||
cout<<out[i]<<" ";
|
||||
}
|
||||
cout<<endl;
|
||||
|
||||
}
|
||||
|
||||
int main(){
|
||||
int n;
|
||||
cout<<"enter the number of elements : ";
|
||||
cin>>n;
|
||||
int arr[n];
|
||||
cout<<"enter the elements\n";
|
||||
for(int i=0;i<n;i++){
|
||||
cin>>arr[i];
|
||||
}
|
||||
rankSort(arr,n);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user