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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:15:29+00:00 2026-05-31T10:15:29+00:00

I have a problem with my homework assignment and I do not know where

  • 0

I have a problem with my homework assignment and I do not know where I went wrong with it. I have to design a function for radix sort with a a buckets and k rounds. I need to preserve the sequence of the list items in the bucket and therefore I need to keep two points for each bucket – to front and rear.
However, when I compile my code and run my test code with 10 numbers that need to be sorted, my output contains only 3 numbers. If its 20 numbers, it prints only 2. Can you help me please? This is my code and thank you for your time. Edit: by leastSigDig i mean Significant Digit i have to change that because its a bad name

#include <cstdlib> // Provides size_t and NULL
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;

struct listnode { struct listnode * next;
                  unsigned long     value; } ;

struct listnode *radixsort (struct listnode *data, int a, int k){
    struct listnode *front [a], *rear [a], *cursor;
    int i=0 , j = 0, leastSigDig,base10num;
    if (data == NULL) {return data;}

    for (i;i<k;i++){
        base10num= pow(a,i);
        cursor = data;
        for (j=0; j<a; j++){
            front [j] = NULL;
            rear [j] = NULL;
        }
        while (cursor != NULL){
            leastSigDig = ((cursor->value)/base10num)%a;
            if (rear [leastSigDig]!= NULL){
                rear[leastSigDig]->next= cursor;
                rear [leastSigDig]= cursor;
            }
            else if (cursor == NULL) {
                rear [leastSigDig] = cursor;
            }
            cursor = cursor->next;
        }

        //Linking
            cursor = NULL;
for (int y=0; y< a-1; y++){
    int z= y+1;
    if (front [y] == NULL)
        continue;
    else if (cursor == NULL){
            cursor = front [y];
            rear [y]->next = front [z];
        }
    else if (cursor != NULL) 
            rear [y]->next = front [z];


    data = cursor;
    }
        }
    }
    return data;
}   


int main(void)
{  
    long i, length=10;
    long a = 10; // working with base 10
    long k = log10(length*a);
    struct listnode *node, *space;
    space =  (struct listnode *) malloc(length*sizeof(struct listnode));
    for( i=0; i< length; i++ ) {
        (space + i)->value = 2*((17*i)%length);
        (space + i)->next = space + (i+1);
    }
    (space+(length-1))->next = NULL;
    node = space;
    struct listnode * temp =node;
    cout<<endl<<"List before radixsort\n" <<endl ;
    while(temp!=NULL)
    {
        cout << temp->value << "\t";
        temp = temp->next;
    }

    node = radixsort(node,a,k);

    listnode *check = node;
    cout << "\n\nList after radixsort \n\n";
    while (check)
    {
        cout << check->value << "\t";
        check = check->next;
    }
    cout << "\n\n";
    exit(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-05-31T10:15:30+00:00Added an answer on May 31, 2026 at 10:15 am

    There is at least one problem here:

    //Linking
    int y= 0;
    
    for (int y; y< a-1; y++){
    

    The variable y in the for loop shadows the y in the outer scope. This means the y inside the loop is uninitialized and you are off into the weeds.

    You should turn up the compiler warning level and pay attention to what it says.

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

Sidebar

Related Questions

This was a homework assignment problem which I know I have incorrectly answered. I
I have this homework problem where I need to use regex to remove every
I have been given a homework assignment where I need to create a captcha
Continuing on this problem , but I'll reiterate: For a homework assignment I have
Hi I have a homework assignment where I need to implement an intersection of
Okay, so I have another question on a prolog homework problem I am struggling
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with fancybox. I want to write a function that will run
For my homework assignment, I need to implement Horners Algorithm for converting between bases.
I am trying to solve a homework problem where I have to return a

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.