import java.io.*; import java.util.*; // NOTICE THE ">" // using > in here means compiler wont let the code in main send in any T type // that does not implement Comparable. Now we do not have to cast the incoming key to a Comparable // in our insertInOrder() method. Compiler now lets us call .compareTo off the dot on the incoming key // without throwing an error. public class LinkedList> { private Node head; // pointer to the front (first) element of the list public LinkedList() { head = null; // compiler does this anyway. just for emphasis } // LOAD LINKED LIST FROM INCOMING FILE @SuppressWarnings("unchecked") public LinkedList( String fileName, boolean orderedFlag ) { head = null; try { BufferedReader infile = new BufferedReader( new FileReader( fileName ) ); while ( infile.ready() ) { if (orderedFlag) insertInOrder( (T)infile.readLine() ); // WILL INSERT EACH ELEM INTO IT'S SORTED POSITION else insertAtTail( (T)infile.readLine() ); // TACK EVERY NEWELEM ONTO END OF LIST. ORIGINAL ORDER PRESERVED } infile.close(); } catch( Exception e ) { System.out.println( "FATAL ERROR CAUGHT IN C'TOR: " + e ); System.exit(0); } } //------------------------------------------------------------- // inserts new elem at front of list - pushing old elements back one place public void insertAtFront(T data) { head = new Node(data,head); } // we use toString as our print public String toString() { String toString = ""; for (Node curr = head; curr != null; curr = curr.next ) { toString += curr.data; // WE ASSUME OUR T TYPE HAS toString() DEFINED if (curr.next != null) toString += " "; } return toString; } // ########################## Y O U W R I T E T H E S E M E T H O D S ######################## public int size() // OF COURSE MORE EFFICIENT to KEEP COUNTER BUT YOU MUST WRITE LOOP { return 0; // YOUR CODE HERE } public boolean empty() { return false; // YOUR CODE HERE } public boolean contains( T key ) { return false; // YOUR CODE HERE } public Node search( T key ) { return null; // YOUR CODE HERE } // TACK A NEW NODE (CABOOSE) ONTO THE END OF THE LIST public void insertAtTail(T data) { // YOUR CODE HERE } // IF YOU DEFINE at the top of this class as // YOU DO NOT HAVE TO CAST TO COMPARABLE AND YOU DO NOT NEED TO SUPPRESS public void insertInOrder(T data) { // YOUR CODE HERE } public boolean remove(T key) { return false; // REPLACE WITH YOUR CODE } public boolean removeAtTail() // RETURNS TRUE IF THERE WAS NODE TO REMOVE { return false; // YOUR CODE HERE } public boolean removeAtFront() // RETURNS TRUE IF THERE WAS NODE TO REMOVE { return false; // YOUR CODE HERE } public LinkedList union( LinkedList other ) { LinkedList union = new LinkedList(); // YOUR CODE HERE return union; } public LinkedList inter( LinkedList other ) { LinkedList inter = new LinkedList(); // YOUR CODE HERE return inter; } public LinkedList diff( LinkedList other ) { LinkedList diff = new LinkedList(); // YOUR CODE HERE return diff; } public LinkedList xor( LinkedList other ) { return null; // REPLACE WITH YOUR CODE } } //END LINKEDLIST CLASS // A D D N O D E C L A S S D O W N H E R E // R E M O V E A L L P U B L I C & P R I V A T E (except toString) // R E M O V E S E T T E R S & G E T T E R S // M A K E T O S T R I N G P U B L I C