#include<iostream>
#include<stdio.h>
usingnamespace std;
void Bucket_Sort(int array[], int n)
{
int i, j;
int count[n];
for (i = 0; i < n; i++)
{
count[i] = 0;
}
for (i = 0; i < n; i++)
{
(count[array[i]])++;
}
for (i = 0, j = 0; i < n; i++)
{
for (; count[i]>0; (count[i])--)
{
array[j++] = i;
}
}
}
int main()
{
int array[100];
int num;
int i;
cout << "Enter How many Numbers : ";
cin >> num;
cout << "\n\n";
cout << "Enter the" << num << "elements to be sorted:\n";
for (i = 0; i < num; i++)
{
cin >> array[i];
}
cout << "\nThe array of elements before sorting : \n";
for (i = 0; i < num; i++)
{
cout << " " << array[i];
}
cout << "\nThe array of elements after sorting : \n";
Bucket_Sort(array, num);
for (i = 0; i < num; i++)
{
cout << " " << array[i];
}
cout << "\n";
system("PAUSE");
return 0;
}
In C++ array sizes must be compile time constants, in your program n is not a compile time constant. I suggest you consider using a std::vector instead.