Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Radix sort Issues??? Help

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Radix sort Issues??? Help

    I am having issues getting this Radix sort program to work properly. I know I am overlooking something but I am at a loss to what it is.

    public class SortArrayAll{
     
    	public static void radixSort(String[] array, int n, int d){
    	    ADTQueue<String>[] sort = new ADTQueue[n];
            for (int k = 0; k < n; k++){ // create ADTQueue based on size of array
                sort[k] = new ADTQueue();
            }
            for(int i=0; i<d;i++){
                for(int j=0; j<n;j++){
                   char num = (array[j].charAt(i));
                   int sort1 = Integer.parseInt(Character.toString(num));
                     sort[sort1].enqueue(array[j]);
                }
               int Counter=0;
                  for(int k=0; k<sort.length;k++){
     
                   while(!sort[k].isEmpty()){
                     array[Counter]=(String)sort[k].dequeue();
                     Counter++;
                   }
     
                   //you need to implement this sorting method
                 }
              }
           }
     
     
    	public static void main(String[] args){
    		String[] array = GenerateData.getData(20);
    		int n = array.length;
    		int d = array[0].length();
     
    		System.out.println("Origianl Data");
    		displayArray(array);
     
    		radixSort(array, n, d);
     
    		System.out.println("\nSorted Data");
    		displayArray(array);
     
    	}
     
    	static <T> void displayArray(T[] array){
    		for(int i=0;i<array.length; i++){
    			System.out.print(array[i]+" ");
    		}
    			System.out.print("\n");
    	}
     
    }
    Last edited by Json; May 12th, 2011 at 02:57 AM. Reason: Added Java highlight tags


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Radix sort Issues??? Help

    Can you explain in more detail what the problem is?

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Radix sort Issues??? Help

    The sort method will only sort single digit variables it will not sort double digit variable correctly.

Similar Threads

  1. Arrays.Sort Help
    By Brandon Seale in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 20th, 2011, 02:32 AM
  2. Timing a sort
    By joshft91 in forum Collections and Generics
    Replies: 1
    Last Post: February 7th, 2011, 05:12 PM
  3. Insertion Sort
    By Kimimaru in forum Algorithms & Recursion
    Replies: 2
    Last Post: December 6th, 2010, 06:26 AM
  4. bubble sort and selection sort on strings
    By Sir Saula in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 3rd, 2010, 09:44 AM
  5. Help with Sort arrays
    By drk in forum Collections and Generics
    Replies: 5
    Last Post: September 6th, 2009, 02:48 AM

Tags for this Thread