So it's true, you can't drag a dead elephant to the water and make him drink.
Search results - LiteratePrograms
No article with exactly the supplied title exists. You can [[:Bucket sort C++|create this article]].
Bucket sort (PHP) (1840 bytes)
Bucket sort (Java) (2054 bytes)
Bucket sort (C) (2023 bytes)
Bucket sort (Python) (1752 bytes)
But no C++
Bucket sort - Wikipedia, the free encyclopedia
... and still, no C++
I even got use to the curl-braces. Now that I know QUANTUM is nearing I got another job for em.
....
....
Thank anon,
Code:
for (int div = 1; !done; div *= 10) { // indexvalue = (a[i]/div) % 10
Not sure what you mean with this.
I never cross-links unless the board don't mine, sometimes. Credit is due. I got to make a pot of coffee or else blow the whole night. Here's his entire master-piece, un-cut ... not totally design for the never-never lands
Code:
#include <iostream>
#include <ctime>
using namespace std;
// The prototype for a sorting function
void BucketSort(int array[], int size);
void BucketSortDummy(int array[], int size); // added
int main()
{
const int array_size = 17;
int int_arry[array_size];
// For continued testing: use a different seed each time
//srand(time(NULL));
// During program development, use the same seed each time
// so that you can see exactly what happens differently
// as you change your program.
srand(87654321);
// For testing, I will use integer values 0-99
for (int i = 0; i < array_size; i++) {
int_arry[i] = rand()% 100;
}
cout << "Initially :";
for (int i = 0; i < array_size; i++) {
cout << " " << int_arry[i];
}
cout << endl;
BucketSortDummy(int_arry,array_size); // added
cout << "After sort:";
for (int i = 0; i < array_size; i++) {
cout << " " << int_arry[i];
}
cout << endl;
//........................................ added by me ... minor change
BucketSort(int_arry,array_size);
cout << "After sort:";
for (int i = 0; i < array_size; i++) {
cout << " " << int_arry[i];
}
cout << endl;
//........................................
system("pause"); // added .. remove this if you like
}
// You can put the source for BucketSort() here or in another file
void BucketSortDummy(int array[], int size) // minor change added
{
// Do nothing for now!
}
void BucketSort(int a[], int size)
{
//Declare an array of ten pointers to int
int *b[10];
/*
Declare an array of ten counters that keep track
of how many ints each b[] array contains at
the end of each loop
*/
int bcount[10];
/*
For each pointer, allocate storage for "size" ints:
so that we will have ten arrays:
b[0] is an array of "size" ints
b[1] is an array of "size" ints
.
.
.
b[9] is an array of "size" ints
*/
for (int i = 0; i < size; i++) {
b[i] = new int[size];
}
/*
We will start with a divisor of 1. Each successive time through the
loop, we will multiply the divisor by 10.
For each element a[i], The digit being used to as an index will be
indexvalue = (a[i]/divisor) % 10
So, the first time through the loop we get the units digit,
the next time we get the hundreds digit,
the next time we get the thousands digit,
.
.
.
Here's the big loop:
Go through a loop over elements of a[], and store elements in the
b[indexvalue] array.
Have a counter for each b[] array that keeps track of how many
elements have been copied there.
Go through a loop over the b[] arrays. For each array copy elements
back to the a[] array. If there are any elements in any b[] array
other than b[0] we go to the top again.
How do we know when we are through with the big loop?
When all of the elements are end up in b[0] and the other
buckets are empty.
*/
// Here's the big loop:
bool done = false;
for (int divisor = 1; !done; divisor *= 10) { //Begin the Big Loop
{
cout << " " << a[divisor];; // added - this was my first try
// old first try
}}}
edit:: bad mouth, math and bad spelling