I need to develop a bucket sorting program to sort elements in an array. I also wanted to display the contents of the Array so I could confirm that I did it correctly. When I run the program it just shows a blank return screen. I feel like I have most of the code, and I not good at trouble shooting without an error code. Any advice would be greatly appreciated.
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace std;
int p;
void bucket_sort(int arr[], int n)
{
// Range of possible numbers.
constint m = 10001;
//an array of buckets need to be created.
int buckets[m];
//Buckets need to be set to zero
for (int i = 0; i < m; ++i)
buckets[i] = 0;
//Add items to the bucket.
for (int i = 0; i < n; ++i)
++buckets[arr[i]];
//Sort. Dont quite know how.
for (int i = 0, j = 0; j < m; ++j)
for (int k = buckets[j]; k > 0; --k)
arr[i++] = j;
}
int main()
{
int array[1000];
//Loop to fill array with random values.
for (int j = 0; j < 1000; j++)
{
j = rand() % 100001;
array[p] = j;
}
// Call the sorting function.
bucket_sort(array, p);
//Display the contents of the array. Hopefully it is sorted.
for (int i = 0; i < p; i++)
{
cout << array[i] << " ";
}
return 0;
}
Put the code you need help with here.