I'm trying to complete a radix sort program, and i cant remember the algorithm to get the specific digit out of a number between 1 and 10000

heres the for loop which calls getdigit:

for( i = 0; i <= 4; i++ ){
    printf("Pass %d: ", i );

    for( j = 0; j < n ; j++ ){

      digit = getdigit( A[j] , i-1 );
      appendanumber( &Bins[digit], a[j] } ;

    refill( A, Bins );

    for( k = 0; k < 20; k++ ) printf(" %d ", A[k] );


any help would be appreciated, after i understand getdigit ill attempt refill and might have a question on that as well

9 Years
Discussion Span
Last Post by monkey_king

oh and incase you didnt know A is an array of random numbers generated earlier in main. n is the amount of numbers, and each number is less than or equal to 10000

getdigit is supposed to return the ones digit number or 10s digit number or whatever then appendanumber will place the full number into the bin according to that digit... via a linked list


I would use modulo and div

that is if I want to extract the second digit of 234

I would (234 %100)/10

The first paranthesis, strips out the 2 such that 34 remains
this slash 10 then calulates how many timis 10 divides 34 without remainder.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.