Trying to make a bucket sort, and display the results.

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.

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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int p;
void bucket_sort(int arr[], int n)

{
	// Range of possible numbers.
	const int 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.
Topic archived. No new replies allowed.