d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Help How To Do A Bucket Sort > C++
Add Reply New Topic New Poll
Member
Posts: 22,502
Joined: Aug 5 2011
Gold: 0.00
Jan 8 2013 06:31pm
I have a couple weeks to get this assignment done and I don't want someone to just do it for me, however I'm confused as to where to start.
If someone could explain to me how this works would be fantastic, maybe provide a small example?

This post was edited by sylz1014 on Jan 8 2013 06:38pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Member
Posts: 22,502
Joined: Aug 5 2011
Gold: 0.00
Jan 8 2013 06:45pm
That helps slightly, although I still don't quite get how it works in the coding part.

e/
I know I'm not explaining myself all to an extent as I should but I'm really tired right now :P

This post was edited by sylz1014 on Jan 8 2013 06:45pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jan 8 2013 06:48pm
Quote (sylz1014 @ Jan 8 2013 07:45pm)
That helps slightly, although I still don't quite get how it works in the coding part.

e/
I know I'm not explaining myself all to an extent as I should but I'm really tired right now :P


what part of this do you not understand?

Code
function bucketSort(array, n) is
 buckets ← new array of n empty lists
 for i = 0 to (length(array)-1) do
   insert array[i] into buckets[msbits(array[i], k)]
 for i = 0 to n - 1 do
   nextSort(buckets[i])
 return the concatenation of buckets[0], ...., buckets[n-1]


1. create your buckets
2. assign everything in the array to a bucket
3. sort each bucket
4. combine all the buckets
Member
Posts: 22,502
Joined: Aug 5 2011
Gold: 0.00
Jan 8 2013 06:52pm
Quote (carteblanche @ 8 Jan 2013 20:48)
what part of this do you not understand?

Code
function bucketSort(array, n) is
 buckets ← new array of n empty lists
 for i = 0 to (length(array)-1) do
   insert array[i] into buckets[msbits(array[i], k)]
 for i = 0 to n - 1 do
   nextSort(buckets[i])
 return the concatenation of buckets[0], ...., buckets[n-1]


1. create your buckets
2. assign everything in the array to a bucket
3. sort each bucket
4. combine all the buckets


I guess I needed that explanation lol, thank's for the help I think I understand what it is now. I will return if I run into any kinds of problem, a nice nap will surely be good for me at this time before I start the actual coding :P
Member
Posts: 22,502
Joined: Aug 5 2011
Gold: 0.00
Jan 18 2013 01:04am
Alright so this is the code I have so far.

#include <iostream>
#include <math.h>

using namespace std;


int digits(int number, int digit)
{
return number/int (pow(10.0,digit))%10;
}

int main()
{
int x, y;
int twoDarray[9][9];
int array[4] = {10,20,30,40};

cout << "Displaying Orignal Order of Array: \n";
for (x = 0; x < 4; x++)
{
cout << array[x] << " ";
}

cout << "\nSorting Array: \n";
}

and now I'm stumped as too continue on what to do.
I'm trying to sort the array by tens, then hundreds, then thousands, etc.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll