Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Radix {
- public Queue sort(Queue inq) throws QueueEmptyException{
- Queue[]list=new Queue[10];
- }
- public int getRadix(int n, int radix){
- return (int)(n/Math.pow(10, radix-1))%10;
- }
- }
- public class Queue {
- private int n;
- private Node first;
- private Node last;
- public int nItems=0;
- public class Node{
- public int data;
- public Node next;
- }
- public Queue(){
- first=null;
- last=null;
- n=0;
- }
- public void add(int n){
- Node current = last;
- last = new Node();
- last.data=n;
- nItems++;
- }
- public int remove() throws QueueEmptyException{
- if(isEmpty()) throw new QueueEmptyException();
- int temp=first.data;
- first = first.next;
- nItems--;
- return temp;
- }
- public boolean isEmpty(){
- return first==null;
- }
- }
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- public class RadixTestor {
- public static void main(String[] args) {
- if(args.length != 1){
- System.err.println("Must supply file name");
- return;
- }
- Radix r = new Radix();
- Queue inq = new Queue();
- try {
- BufferedReader reader = new BufferedReader(new FileReader(args[0]));
- String line = null;
- System.out.println("read file and echo input");
- while ((line=reader.readLine()) != null) {
- System.out.println(line);
- inq.add(Integer.parseInt(line));
- }
- System.out.println("sort");
- Queue outq = r.sort(inq);
- System.out.println("display sorted numbers");
- while(!outq.isEmpty()){
- int n = outq.remove();
- System.out.println(n);
- }
- } catch (FileNotFoundException e) {
- System.err.println("Could not read file "+args[0]);
- } catch (IOException e) {
- e.printStackTrace();
- } catch (QueueEmptyException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- 170
- 45
- 75
- 90
- 2
- 24
- 802
- 66
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement