forked from AllAlgorithms/cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrank_sort.cpp
54 lines (46 loc) · 1.06 KB
/
rank_sort.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <math.h>
using namespace std;
void rankSort(int A[], int low, int high)
{
int R[high-low+1];
for(int i=0; i<high-low+1; i++)
R[i] = 1;
for(int i=low+1; i<=high; i++)
{
for(int j=low;j<i;j++)
{
if(A[i] >= A[j])
R[i-low]++;
else
R[j-low]++;
}
}
int U[high-low+1];
for(int i=0;i<high-low+1;i++)
U[R[i]] = A[i+low];
for(int i=0;i<high-low+1;i++)
A[i+low] = U[i+1];
}
int mod(int i)
{
if (i<0)
i=-i;
return i;
}
int main()
{
int n;
cout<<"enter the total no. of entries"<<endl;
cin>>n;
int houses[n];
cout<<"enter the entries"<<endl;
for (int i = 0; i < n; ++i)
{
cin>>houses[i];
}
rankSort(houses,0,n-1);
for(int i=0;i<n;i++)
cout<<houses[i] << " ";
return 0;
}