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 8929649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:43:11+00:00 2026-06-15T08:43:11+00:00

I have been trying to understand this code for hours unsuccessfully. I wrote my

  • 0

I have been trying to understand this code for hours unsuccessfully. I wrote my own version of bead sort algorithm however it is so slow.
I want to understand why this one works so much more quickly.
Here’s info about the bead sort algorithm:
http://demonstrations.wolfram.com/ExtendedBeadSort/
Can you please help me to understand how this algorithm works?

#include <iostream>
#include <vector>

using std::cout;
using std::vector;

void distribute(int dist, vector<int> &List) {
    //*beads* go down into different buckets using gravity (addition).
    if (dist > List.size() )
        List.resize(dist); //resize if too big for current vector

    for (int i=0; i < dist; i++)
        List[i]++;
}

vector<int> beadSort(int *myints, int n) {
    vector<int> list, list2, fifth (myints, myints + n);
    cout << "sakums\n";
    cout << myints<< "\n";
 //   for (vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it) cout << " " << *it << "\n";
    cout << "beigas\n";

    cout << "#1 Beads falling down: ";
    for (int i=0; i < fifth.size(); i++)
        distribute (fifth[i], list);
    cout << '\n';

    cout << "\nBeads on their sides: ";
    for (int i=0; i < list.size(); i++)
        cout << " " << list[i];
    cout << '\n';

    //second part

    cout << "#2 Beads right side up: ";
    for (int i=0; i < list.size(); i++)
        distribute (list[i], list2);
    cout << '\n';

    return list2;
}

int main() {
    int myints[] = {734,3,1,24,324,324,32,432,42,3,4,1,1};
    vector<int> sorted = beadSort(myints, sizeof(myints)/sizeof(int));
    cout << "Sorted list/array";
    for(unsigned int i=0; i<sorted.size(); i++)
        cout << sorted[i] << ' ';
    system("PAUSE");
    return 0;
}
  • 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-06-15T08:43:12+00:00Added an answer on June 15, 2026 at 8:43 am

    Because of how distribute works:

    Each of the other numbers contribute “beads” to the slots – there are 13 numbers so slot 1 has 13 in it when it finishes the first pass.

    it “distributes” beads in “columns” I.e when you print it on its side, there are now 734 slots – the largest number.

    When distribute runs again it shifts the “beads” down by summing the columns – it will perform a number of additions dependent on the max element * The number of numbers – plus memory allocations

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

Sidebar

Related Questions

okay i have been trying to understand this for hours i am learning VB
I have been trying to understand this code template <typename T, typename _Prd =
i have been trying to understand the pack function. I'm having trouble on this
I have been trying to solve this on my own but can't find a
hey I have been trying for hours and I don't understand why the following
I have been trying to get this code to work for a while now
I have been trying to understand the way ActionScript's events are implemented, but I'm
So, I have been trying to understand Socket.io lately, but I am not a
I have been trying to setup git for our web development team unsuccessfully. Some
I have been trying to create a ListView which I can sort using drag

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.