-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathbucketsort.c
59 lines (58 loc) · 839 Bytes
/
bucketsort.c
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
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a[10][20],count[10]={0};
int i,n,ele,x,y;
printf("enter the elements between 0 and 99\n");
printf("enter the number of elements\n");
scanf("%d",&n);
printf("enter %d elements\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&ele);
int tplace=ele/10;
a[tplace][count[tplace]]=ele;
count[tplace]++;
}
for(i=0;i<10;i++)
{
if(count[i]==0)
{
continue;
}
else
{
int noe=count[i];
for(x=0;x<noe-1;x++)
{
for(y=0;y<noe-x-1;y++)
{
if(a[i][y]>a[i][y+1])
{
int z;
z=a[i][y];
a[i][y]=a[i][y+1];
a[i][y+1]=z;
}
}
}
}
}
printf("elements afetr sorting\n");
for(i=0;i<10;i++)
{
if(count[i]==0)
{
continue;
}
else
{
int w;
for(w=0;w<count[i];w++)
{
printf("%d ",a[i][w]);
}
}
}
}