Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. public class Radix {
  2. public Queue sort(Queue inq) throws QueueEmptyException{
  3. Queue[]list=new Queue[10];
  4.  
  5.  
  6. }
  7. public int getRadix(int n, int radix){
  8. return (int)(n/Math.pow(10, radix-1))%10;
  9. }
  10. }
  11.  
  12. public class Queue {
  13. private int n;
  14. private Node first;
  15. private Node last;
  16. public int nItems=0;
  17.  
  18. public class Node{
  19. public int data;
  20. public Node next;
  21.  
  22. }
  23. public Queue(){
  24. first=null;
  25. last=null;
  26. n=0;
  27. }
  28. public void add(int n){
  29. Node current = last;
  30. last = new Node();
  31. last.data=n;
  32. nItems++;
  33. }
  34.  
  35.  
  36.  
  37. public int remove() throws QueueEmptyException{
  38. if(isEmpty()) throw new QueueEmptyException();
  39. int temp=first.data;
  40. first = first.next;
  41. nItems--;
  42. return temp;
  43.  
  44. }
  45. public boolean isEmpty(){
  46. return first==null;
  47. }
  48. }
  49.  
  50. import java.io.BufferedReader;
  51. import java.io.FileNotFoundException;
  52. import java.io.FileReader;
  53. import java.io.IOException;
  54.  
  55. public class RadixTestor {
  56.  
  57. public static void main(String[] args) {
  58. if(args.length != 1){
  59. System.err.println("Must supply file name");
  60. return;
  61. }
  62. Radix r = new Radix();
  63. Queue inq = new Queue();
  64. try {
  65. BufferedReader reader = new BufferedReader(new FileReader(args[0]));
  66. String line = null;
  67. System.out.println("read file and echo input");
  68. while ((line=reader.readLine()) != null) {
  69. System.out.println(line);
  70. inq.add(Integer.parseInt(line));
  71. }
  72. System.out.println("sort");
  73. Queue outq = r.sort(inq);
  74. System.out.println("display sorted numbers");
  75. while(!outq.isEmpty()){
  76. int n = outq.remove();
  77. System.out.println(n);
  78. }
  79. } catch (FileNotFoundException e) {
  80. System.err.println("Could not read file "+args[0]);
  81. } catch (IOException e) {
  82. e.printStackTrace();
  83. } catch (QueueEmptyException e) {
  84. // TODO Auto-generated catch block
  85. e.printStackTrace();
  86. }
  87.  
  88. }
  89.  
  90. }
  91.  
  92. 170
  93. 45
  94. 75
  95. 90
  96. 2
  97. 24
  98. 802
  99. 66
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement