-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounting_sort.cpp
More file actions
41 lines (36 loc) · 883 Bytes
/
Copy pathcounting_sort.cpp
File metadata and controls
41 lines (36 loc) · 883 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
#include<cstdio>
#include<cstring>
using namespace std;
#define p printf
#define s scanf
int main()
{
int a,n,i;
int arr[100],t[100],result[100];
p("\nThis program is not allowed for negative number.\n");
p("\nEnter number of data: ");
while(s("%d",&a)==1)
{
p("\nEnter data below:\n");
for(i=1;i<=a;++i)
s("%d",&arr[i]);
p("\nEnter max number in data: ");
s("%d",&n);
memset(t,0,sizeof(t));
for(i=1;i<=a;++i)
t[arr[i]]=t[arr[i]]+1;
for(i=1;i<=n;++i)
t[i]=t[i]+t[i-1];
for(i=1;i<=a;++i)
{
result[t[arr[i]]]=arr[i];
t[arr[i]]=t[arr[i]]-1;
}
p("\nThe sorted output is given below:\n");
for(i=1;i<=a;++i)
p("%d ",result[i]);
p("\n\n");
p("\nEnter number of data: ");
}
return 0;
}