Results 1 to 3 of 3

Thread: Radix Sort

  1. #1
    Ronald Spina is offline Member
    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Default Radix Sort

    Hi guys,

    I have just finished implementing my radix sort. Seems to be working fine within the first and second pass, but not in the third and fourth pass. Anyone could please find what i am doing wrong!
    Please help me cause i really want to make this Radix Sort work!! I think I have some bugs in my program but I cant find where!! I also noted that the integers a being duplicated in the output.
    Java Code:
    import java.util.Scanner;
    public class RadixSort 
    {
    
    	    public static void main(String[] args)
    		{
    			Scanner userinput = new Scanner(System.in);
    			System.out.print("Please enter the size of the array. ");
    			//User is prompted to enter the size of the array.
    			int count = userinput.nextInt();
    
    			int[] numbers = new int[count];
    			QueueLinkedList[] queue = new QueueLinkedList[10];
    	
    			for(int i=0; i<queue.length; i++)
    			{
              		queue[i] = new QueueLinkedList();
            	}
    			
    			//Generates random integers.
    			for(int i=0; i<numbers.length; i++)
    			{
    				numbers[i] = (int)(Math.random()*1001);
    				System.out.print(numbers[i]+", ");
    			}
      			System.out.println();
      			     	
    			for(int j=1; j<=4; j++)
    			{
    				for(int i=0; i<numbers.length; i++)
    				{
    					int  temp = 0;
    					queue[getRadix(numbers[i],j)].enqueue(numbers[i]);
    				}
    
    				for(int i=0; i<queue.length; i++)
    				{
    					int index=0;
    					while(!queue[i].isEmpty())
    						{					
    							numbers[index] = queue[i].dequeueInt();
    							System.out.print(numbers[index]+", ");
    							index++;
    						}
    				}System.out.println();
    			}
    					
    		}
        	public static int getRadix(int number, int radix)
        	{
    			int result = (int)(number / Math.pow(10,radix-1)) % 10;
    			return result;
    		}
    
    	
    }
    --------------------Configuration: <Default>--------------------
    Please enter the size of the array. 20
    580, 152, 221, 85, 564, 79, 526, 692, 688, 635, 409, 440, 582, 81, 874, 440, 975, 840, 919, 856,
    580, 440, 440, 840, 221, 81, 152, 692, 582, 564, 874, 85, 635, 975, 526, 856, 688, 79, 409, 919,
    409, 409, 919, 919, 526, 635, 840, 440, 440, 840, 856, 564, 79, 79, 874, 975, 688, 582, 81, 692,
    81, 79, 81, 409, 440, 440, 582, 564, 526, 582, 692, 692, 688, 635, 874, 840, 856, 975, 975, 919,
    975, 975, 919, 635, 564, 79, 526, 692, 688, 635, 409, 440, 582, 81, 874, 440, 975, 840, 919, 856,

    Process completed.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Radix Sort

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

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

Similar Threads

  1. Parallel Radix Sorting client/server
    By Darksurf in forum Networking
    Replies: 3
    Last Post: 04-29-2011, 07:07 AM
  2. Null Pointer Exception in Radix Sort
    By resspopv in forum New To Java
    Replies: 7
    Last Post: 11-19-2010, 05:21 AM
  3. Radix Sort Problem !!!!
    By javanew in forum Advanced Java
    Replies: 2
    Last Post: 09-21-2010, 04:33 AM
  4. Using Merge Sort to sort an ArrayList of Strings
    By coldfire in forum New To Java
    Replies: 3
    Last Post: 03-13-2009, 01:03 AM
  5. How to sort a list using Bubble sort algorithm
    By Java Tip in forum Algorithms
    Replies: 3
    Last Post: 04-29-2008, 08:04 PM

Posting Permissions

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