import java.io.*;
import DataStructures.*;

/*
  A template main class for handling I/O for radix sort
*/
public class RadixSort {
    /*
      Method to read a file of integers and put in a linked list
    */
    public static LinkedList convertToList(String filename) throws IOException{
	LinkedList returnList = new LinkedList();
	LinkedListItr itr = returnList.zeroth();

	FileReader fileReader = new FileReader(filename);
	BufferedReader bufferedReader = new BufferedReader(fileReader);
	String inputString = bufferedReader.readLine();
	while (inputString != null) {
	    try {
		int entry = Integer.parseInt(inputString);
		returnList.insert(new Integer(entry), itr);
		itr.advance();
	    }
	    catch (NumberFormatException e) {
		System.err.println("Not an integer");
	    }
	    inputString = bufferedReader.readLine();
	}
	LinkedList.printList(returnList);
	return returnList;
    }

    /*
      Main method for radix sort algorithm
    */
    public static void main(String[] args) throws IOException {

	// Check for the proper number of arguments.
	if (args.length != 2) {
	    System.err.println("USAGE: java RadixSort <number passes> " +
			       "<file>\n");
	    System.exit(1);
	}

	// Read the command line
	int numPasses;
	try {
	    numPasses = Integer.parseInt(args[0]);
	}
	catch (NumberFormatException e) {
	    System.err.println("Number of passes must be an integer");
	    System.exit(1);
	}

	// You should also check that the number of passes is greater than
	// 0, and that the integers in the input file have at most numPasses
	// digits
	String file = args[1];

	// Initially, read the given file into a linked list.
	LinkedList fileList = convertToList(file);
    
	// Your radix sort algorithm goes here

    }
}




