A friendly place for programming greenhorns!
Big Moose Saloon
Search

Java FAQ

Recent Topics

Flagged Topics

Hot Topics

Zero Replies
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
cant get my radix sort working:(
Andrew Hodel
Greenhorn
Joined: Apr 04, 2013
Posts: 10
posted
Apr 04, 2013 00:38:10
0
i need to write code to sort an arbitrary number of digits and random values. my code as of now just replaces the first position with the last position!
ive been working at this all day and just cant figure out where its bugging out. please help
import java.util.LinkedList; import java.util.Scanner; public class pt2 { int[] mine; int digits; Scanner sn = new Scanner(System.in); public pt2() { makeArray(); add(); } @SuppressWarnings({ "unchecked", "rawtypes" }) void RADIX(int[] kiki, int digi){ while(digi<=digits){ LinkedList<Integer> l0 = new LinkedList<Integer>(); LinkedList<Integer> l1 = new LinkedList<Integer>(); LinkedList<Integer> l2 = new LinkedList<Integer>(); LinkedList<Integer> l3 = new LinkedList<Integer>(); LinkedList<Integer> l4 = new LinkedList<Integer>(); LinkedList<Integer> l5 = new LinkedList<Integer>(); LinkedList<Integer> l6 = new LinkedList<Integer>(); LinkedList<Integer> l7 = new LinkedList<Integer>(); LinkedList<Integer> l8 = new LinkedList<Integer>(); LinkedList<Integer> l9 = new LinkedList<Integer>(); LinkedList[] cap ={l0,l1,l2,l3,l4,l5,l6,l7,l8,l9}; for( int j=0;j<kiki.length;j++){ int k=0; while(k<10){ //need to put the number in the correct LL but how int jk = digital(kiki[j],(int)(Math.pow(10,digi))); if(jk==k){ cap[k].add(kiki[j]); k=11; } k++; } } int i = 0; while(i<kiki.length){ int p=0; while(p<10){ while(cap[p].isEmpty()==false){ kiki[i]=(int) cap[p].removeFirst(); } p++; } i++; } digi++; } } public int digital(int num, int pos){ int i = (int) (num % Math.pow(10,pos)); i= (int)(i/Math.pow(10, pos1)); return i; } void add(){ int i=0; while(i<mine.length){ mine[i] = (int)(Math.random()*Math.pow(10, digits)); i++; } } void makeArray(){ System.out.println("Max size?"); mine = new int[sn.nextInt()]; System.out.println("Max digits?"); if(digits<0){ System.out.println("bad USer"); }else{ digits = sn.nextInt(); } } }
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 46410
51
posted
Apr 04, 2013 01:44:33
0
What is the algorithm for radix sort? Write it down on paper, then convert that to pseudo‑code, before trying to write code.
I agree. Here's the link:
http://aspose.com/filetools
subject: cant get my radix sort working:(
Similar Threads
Check Boxes
try catch finally
Array questions about Object[]
why i am not getting the proper format of the following code
All times are in JavaRanch time: GMT6 in summer, GMT7 in winter