Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7511683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:37:34+00:00 2026-05-29T23:37:34+00:00

A book I have says this: a) Place each value of the one-dimensional array

  • 0

A book I have says this:

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 am having a lot of trouble trying to understand and implement this. So far I have:

void b_sort(int sarray[], int array_size) {
    const int max = array_size;
    for(int i = 0; i < max; ++i)
        int array[i] = sarray[i];

    int bucket[10][max - 1];
}

I’m thinking that in order to sort them by ones, tens, hundreds, etc, I can use this:

for(int i = 0; i < max; ++i)
    insert = (array[i] / x) % 10;
    bucket[insert];

where x = 1, 10, 100, 1000, etc. I am totally lost on how to write this now.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:37:35+00:00Added an answer on May 29, 2026 at 11:37 pm

    Here’s a bucket sort based on the info in the OP question.

    void b_sort(int sarray[], int array_size) {
        const int max = array_size;
        // use bucket[x][max] to hold the current count
        int bucket[10][max+1];
        // init bucket counters
        for(var x=0;x<10;x++) bucket[x][max] = 0;
        // main loop for each digit position
        for(int digit = 1; digit <= 1000000000; digit *= 10) {
            // array to bucket
            for(int i = 0; i < max; i++) {
                // get the digit 0-9
                int dig = (sarray[i] / digit) % 10;
                // add to bucket and increment count
                bucket[dig][bucket[dig][max]++] = sarray[i];
            }
            // bucket to array
            int idx = 0;
            for(var x = 0; x < 10; x++) {
                for(var y = 0; y < bucket[x][max]; y++) {
                    sarray[idx++] = bucket[x][y];
                }
                // reset the internal bucket counters
                bucket[x][max] = 0;
            }
        }
    }
    

    Notes Using a 2d array for the bucket wastes a lot of space… an array of queues/lists usually makes more sense.

    I don’t normally program in C++ and the above code was written inside the web browser, so syntax errors may exist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i am reading this python book and one of the exercises says: Write
Each book can have many authors. And each author can author many books. class
I came across this class while reading a C# book and have some questions.
I have this in URL file (r'^new/(?P<object_class>\w+)/(?P<action>\w+)/(?P<object_id>\d+)/$', create_object) NOw for URL like /new/book/edit/5 it
I have extracted this from the book called Rhomobile Beginner's Guide Abhishek Nalwaya Published
I have seen Java code that says something like: SomeClass.this.someMethod(someArg); Blah(AnotherClass.class); Blah(YAClass.this); What do
This is an example I have seen in the Effective C# book: private BindingList<PayrollData>
(This question is more for the people who have access to the book, It's
I have a book that says to do the following. Add a JAVA_HOME and
It seems the code and the book have been relegated to the foundation of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.