Results 1 to 2 of 2
  1. #1
    shinjuo is offline Member
    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Default Learning Radix sort

    I understand how radix sort works. You take a set of numbers and your sort by the lowest part of each number. So if you have 345 236 and 786 you would sort by 1's position, 10's position, and 100's position. My book explains all this easily enough. It does not however give any explanation of how you about sorting a digit then the next and so on. I am writing a radix sort that uses counting sort as the stable sort and I am not completely sure how to maintain which digit position during sort. I have the counting sort working fine but I am not sure how to use the radix sort and then implement that into the counting sort

    Java Code:
    public static int[] radixSort(int[] A, int d){
            int[] B = new int[A.length];
            int[] C = new int[d + 1];
            for(int i = 0; i < d; i++){
                for(int j = 0; j <= d; j++){
                    C[j] = 0;
                }
                for(int j = 0; j < A.length; j++){
                    C[A[j]] = C[A[j]] + 1;
                }
                for(int j = 1; j <= d; j++){
                    C[j] = C[j] + C[j-1];
                }
                for(int j = A.length - 1; j >= 0; j--){
                    B[C[A[j]]-1] = A[j];
                    C[A[j]] = C[A[j]] - 1;
                }
            }
            return B;
        }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: Learning Radix sort

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Radix Sort
    By Ronald Spina in forum New To Java
    Replies: 2
    Last Post: 12-15-2012, 12:33 AM
  2. Replies: 12
    Last Post: 06-14-2011, 04:55 PM
  3. Parallel Radix Sorting client/server
    By Darksurf in forum Networking
    Replies: 3
    Last Post: 04-29-2011, 07:07 AM
  4. Null Pointer Exception in Radix Sort
    By resspopv in forum New To Java
    Replies: 7
    Last Post: 11-19-2010, 05:21 AM
  5. Radix Sort Problem !!!!
    By javanew in forum Advanced Java
    Replies: 2
    Last Post: 09-21-2010, 04:33 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •