-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountsort1.c
More file actions
63 lines (57 loc) · 855 Bytes
/
countsort1.c
File metadata and controls
63 lines (57 loc) · 855 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
63
#include<stdio.h>
void countsort(int a[],int n)
{
int max,i,j;
max=findmax(a,n);
int c[max+1];
for(i=0;i<max+1;i++)
c[i]=0;
for(i=0;i<n;i++)
c[a[i]]++;
i=0;
j=0;
while(i<max+1)
{
if(c[i]>0)
{
a[j++]=i;
c[i]--;
}
else
i++;
}
}
int findmax(int arr[],int n)
{
int i,max;
max=arr[0];
for(i=1;i<n;i++)
{
if(arr[i]>max)
max=arr[i];
}
return(max);
}
void display(int arr[], int n)
{
int i;
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
}
void main()
{
int arr[6]={20,12,10,3,22,34};
int n=6;
int i;
// printf("Enter number of elements in array - ");
// scanf("%d",&n);
// int arr[n];
// printf("Enter elements in the array\n");
//
// for(i=0;i<n;i++)
// {
// scanf("%d",&arr[i]);
// }
countsort(arr,n);
display(arr,n);
}