-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcount_sort.cpp
More file actions
executable file
·62 lines (55 loc) · 940 Bytes
/
count_sort.cpp
File metadata and controls
executable file
·62 lines (55 loc) · 940 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<iostream>
#define k 50
using namespace std;
class count
{
public:int a[20],b[20];
int n;
void create();
int f[k+1],c[k+1];
void sort();
count()
{ for(int i=0;i<k+1;i++)
{ f[i]=c[i]=0;}
}
int cou(int ,int );
};
int main()
{
int a,b;
count ob;
ob.create();
ob.sort();
cout<<"enter the range a,b"<<endl;
cin>>a>>b;
int n;
n=ob.cou(a,b);
cout<<" there are "<<n<<" no.s btwn a,b"<<endl;
return 0;
}
int count::cou(int a,int b)
{
return(c[b]-c[a-1]);
}
void count::create()
{
cout<<"enter no. of values"<<endl;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
}
void count::sort()
{
for(int i=0;i<n;i++)
f[a[i]]++;
c[0]=f[0];
for(int i=1;i<k+1;i++)
c[i]=c[i-1]+f[i];
for(int i=n-1;i>=0;i--)
{
b[c[a[i]]-1]=a[i];
c[a[i]]--;
}
for(int i=0;i<n;i++)
cout<<b[i]<<" ";
}