BUCKET SORT@myself
#include<stdio.h>
void Bucket_Sort(int array[], int n)
{
int i, j,k=0;
int count[100];
for (i = 0; i < 100; i++)
count[i] = 0;
for (i = 0; i < n; i++)
(count[array[i]])++;
for (i = 0;i < 100; i++)
{
for (j=0;j<count[i];j++)
{
array[k]=i;
k+=1;
}
}
}
int main()
{
int array[100], i, num;
scanf("%d", &num);
for (i = 0; i < num; i++)
{scanf("%d", &array[i]);}
printf("befor sorting\n");
for (i = 0; i < num; i++)
{ printf("%d ", array[i]);}
printf("\nafter sorting \n");
Bucket_Sort(array, num);
for (i = 0; i < num; i++)
{ printf("%d ", array[i]); }
printf("\n");
return 0;
}
void Bucket_Sort(int array[], int n)
{
int i, j,k=0;
int count[100];
for (i = 0; i < 100; i++)
count[i] = 0;
for (i = 0; i < n; i++)
(count[array[i]])++;
for (i = 0;i < 100; i++)
{
for (j=0;j<count[i];j++)
{
array[k]=i;
k+=1;
}
}
}
int main()
{
int array[100], i, num;
scanf("%d", &num);
for (i = 0; i < num; i++)
{scanf("%d", &array[i]);}
printf("befor sorting\n");
for (i = 0; i < num; i++)
{ printf("%d ", array[i]);}
printf("\nafter sorting \n");
Bucket_Sort(array, num);
for (i = 0; i < num; i++)
{ printf("%d ", array[i]); }
printf("\n");
return 0;
}
Comments
Post a Comment