How Do I Do A Bucket Sort?

Alright, so I have an assignment and this is what needs to be done.

a) Place each value of the one-dimensional array into a row of the bucket array based on the value's ones digit. For example, 97 is placed in row 7, 3 is placed in row 3, and 100 is placed in row 0. This is called a "distribution pass."

b) Loop through the bucket array row by row, and copy the values back to the original array. This is called a "gathering pass." The new order of the preceding values in the one-dimensional array is 100, 3, and 97.

c) Repeat this process for each subsequent digit position.

I figured I'll take it to the next step and make the use input the size of the array themselves. So I got the array down, but I still can't figure out how to sort it using this method, I've done much research and I still just don't get it.

tl;dr This is my code, please help me do a bucket sort.

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
int i;
cout << "Input array size: ";
int size;
cin >> size;
cout << endl;

int* array = new int [size];
delete[] array;

srand((unsigned)time(0));

for(i = 0; i < size; i++)
{
array[i] = (rand()%1000)+1;

cout << array[i] << " ";
}
}
Topic archived. No new replies allowed.