// Page 247-248 public class Linkedlist { private ListNode head; public Linkedlist() { head = null; } public void print() { ListNode position = head; while(position != null) { System.out.print(position.getData() + " "); position = position.getLink(); } System.out.println(); } public int length() { int count = 0; ListNode position = head; while(position != null) { count ++; position = position.getLink(); } return count; } public void insertTop(T addData) { head = new ListNode(addData, head); } public void removeTop() { if(head != null) head = head.getLink(); else { System.out.println("An empty list."); System.exit(0); } } }