-
Notifications
You must be signed in to change notification settings - Fork 0
/
count sort.cpp
47 lines (46 loc) · 972 Bytes
/
count 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
#include<iostream>
using namespace std;
class count{
int siz,arr[40],count[50],out[50],i;
public:
void disp(){
out[i]=arr[i];
int i=0;
out[i]=arr[i];
for( i=0;i<siz;i++){
cout<<arr[i];
}
}
void ary(){
int n;
cout<<"enter siz";
cin>>siz;
for(int i=0;i<siz;i++){
cout<<"enter elements";
cin>>arr[i];
}
}
void sort(){
int*count=new int[siz+1];
for(int i=0;i<=siz;i++){
count[i]=0;
}
for(int i=0;i<siz;i++){
count[arr[i]]++;
}
for(int i=1;i<=siz;i++){
count[i]+=count[i-1];
}
int *out=new int[siz];
for(int i=siz-1;i<0;i--){
out[count[arr[i]]-1] = arr[i]; count[arr[i]]--;
}
}
};
int main(){
count c;
c.ary();
c.sort();
c.disp();
return 0;
}