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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:36:48+00:00 2026-06-18T09:36:48+00:00

I’ve tried for a couple hours to get this working, but for whatever reason

  • 0

I’ve tried for a couple hours to get this working, but for whatever reason I can’t get my array to print correctly. Here is my code (.txt file below)

//
//  main.cpp
//  cs498 -mp1

#include<iostream>
#include<stdlib.h>
#include <fstream>
#include<time.h>

int sortsize=1000;
int seed=1;

using namespace std;

void readfile(int *input, int size)

{

}

void writefile(int *input, int size)
{
    ofstream myfile;
    myfile.open ("example.txt");
    myfile << "Radix Sort\n";

    for(int i=0; i<size; i++)
        myfile << input[i] << endl;
    myfile.close();

}


void radixsort(int *a, int arraySize)
{
    int i, bucket[sortsize], maxVal = 0, digitPosition =1 ;
    for(i = 0; i < arraySize; i++) {
        if(a[i] > maxVal) maxVal = a[i];
    }

    int pass = 1; 
    while(maxVal/digitPosition > 0) {
        // reset counter 
        int digitCount[10] = {0};

        // count pos-th digits (keys) 
        for(i = 0; i < arraySize; i++)
            digitCount[a[i]/digitPosition%10]++;

        // accumulated count 
        for(i = 1; i < 10; i++)
            digitCount[i] += digitCount[i-1];

        // To keep the order, start from back side
        for(i = arraySize - 1; i >= 0; i--)
            bucket[--digitCount[a[i]/digitPosition%10]] = a[i];

        for(i = 0; i < arraySize; i++)
            a[i] = bucket[i];

        cout << "pass #" << pass++ << ": ";
        digitPosition *= 10;
    } 

}

void ccradixsort(int *array /* you will need more arguments */)
{

}

int main(int argc, char *argv[])
{
    clock_t start, end;
    int *sortarray;
    int *input;

    if(argc > 1)
        sortsize = atoi(argv[1]);

    sortarray = (int *) malloc(sortsize * sizeof(int));
    input = (int *) malloc(sortsize * sizeof(int));

    if(/*argc == 3*/ true)
    {
        seed = atoi(argv[2]);
        for(int i = 0; i < sortsize; i++)
        {
            input[i] = rand();      
        }
    }
    else
    {
        readfile(input,sortsize);
    }

    for(int i = 0; i < sortsize; i++)
    {
        sortarray[i] = input[i];
    }

    start = clock();
    radixsort(sortarray, sizeof(sortarray));
    end = clock();

    cout << "Sorted in " << (double)(end - start)/CLOCKS_PER_SEC << " seconds by radixsort()" << endl;
    writefile(sortarray, sortsize);

/*  
    for(int i = 0; i < sortsize; i++)
    {
        sortarray[i] = input[i];
    }

    start = clock();
    ccradixsort(sortarray);
    end = clock();

    cout << "Sorted in " << (double)(end - start)/CLOCKS_PER_SEC << " seconds by ccradixsort()" << endl;

    //if(argc != 3)
    //  writefile(sortarray, sortsize);
*/
}

And here’s a portion of the text file it generates:

>Radix Sort

>16807  
>101027544  
>282475249  
>470211272  
>984943658  
>1144108930  
>1457850878  
>1622650073  
>1458777923  
>2007237709  
>823564440  
>1115438165 
  • 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-18T09:36:50+00:00Added an answer on June 18, 2026 at 9:36 am

    Here:

    radixsort(sortarray, sizeof(sortarray));
    

    Because sortarray is an int*, sizeof(sortarray) is only 4 or 8 (depending on your target).

    You should probably use sortsize like you do elsewhere.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am confused How to use looping for Json response Array in another Array.

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.