CS 211 - 10/21/16 Linked Lists in Java Typically 2 classes are used one class for the nodes in the list one class for the list itself // must be in the file Node.java public class Node =========================== // could exist in a file not named Node.java // often the Node class is put into a List.java file class Node { private Integer elem; private Node next; // getters and setters public int getElem () { return elem; } public void setElem (int e) { elem = e; } public Node getNext () { return next; } public void setNext (Node n) { next = n; } // constructor Node (int e, Node n) { elem = e; next = n; } Node () { elem = -999; next = null; } } public class List { Node head; List () { head = null; } public void addToFront( int val) { Node temp = new Node (val, head ); head = temp; } } ============================ // code that uses the List class ...main( ....) { // java style List l1 = new List(); l1.addToFront( 5 ); // C-style requires the user understand how the Node // class is meant to be implemented Node n1 = null;