whiteflags, I see what you mean and glad you understand. I'm so happy I'm taking a JAVA course this semester. It's helping me to understand C++ ten time better every week. Now I get it ...
Code:
// http://en.literateprograms.org/Bucket_sort_(Java)
// BucketSort Array
#include <vector>
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void bucketSorter(int DATA[],int length, int COUNT);
int main()
{
int DATA[] = {90, 90, 90, 80, 70, 60, 50, 40, 30, 30};
int element = sizeof(DATA)/sizeof(int);
int COUNT = DATA[0];
// .......................................
cout << "Original order :";
for (int i = 0; i < element; i++) {
cout << " " << DATA[i]; }
cout << endl;
cout << endl;
// .......................................
cout << "After Bucket sort:";
bucketSorter(DATA, element, COUNT);
getchar();
}
// ..............................................
// ..............................................
void bucketSorter(int DATA[],int length, int COUNT)
{
int* bSort = new int[COUNT];
int SIZE = length;
for( int B = 0 ; B <= COUNT ; ++B ) {
bSort[B] = 0; }
for(int A = 0 ; A < SIZE ; ++A) {
++bSort[DATA[A]]; }
for( int A = 0, B = 0 ; B <= COUNT ; ++B ) {
for(int C = bSort[B] ; C > 0 ; --C ) {
DATA[A++] = B; } } // it matters here A++ not ++A
for( int A = 0 ; A < SIZE ; ++A )
{
cout << " " << DATA[A];
}
cout << endl;
}
This is my code and it do work! ... but when I cup and paste it from this link, it don't work so I don't know who has a possible bug.