-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrankSort.cpp
More file actions
48 lines (41 loc) · 778 Bytes
/
rankSort.cpp
File metadata and controls
48 lines (41 loc) · 778 Bytes
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
#include<iostream><limits.h>
using namespace std;
int* ranksort(int* &array,int n){
int i,j;
int *b = new int[n];
int *rank = new int[n];
for(i=1;i<n;i++){
for(j=0;j<i;j++){
if(array[j] > array[i]){
rank[j]++;
}
else {
rank[i]++;
}
}
}
for(i=0;i<n;i++){
b[rank[i]] = array[i];
}
array = b;
return rank;
}
int main(){
int *a = new int[5];
a[0] = 5;
a[1] = 7;
a[2] = 7;
a[3] = 4;
a[4] = 10;
int *r;
r = ranksort(a,5);
cout<<"ranks are :";
for(int i=0;i<5;i++){
cout<<r[i]<<" ";
}
cout<<endl<<"sorted array is :";
for(int i=0;i<5;i++){
cout<<a[i]<<" ";
}
cout<<endl;
}