B: ref.link C: ref.link.link D: ref.link.link.info
public void printList() { Node temp = head; if (temp == null) System.out.println("The list is empty."); while (temp != null) { System.out.println(temp.info); temp = temp.link; } }
public int sum () { int result = 0; Node temp = head; while (temp != null) { result += temp.info; temp = temp.link; } return result; }
public void deleteFirst() { if (head == null) System.out.println("The list is empty, nothing to delete."); else if (head.link == null) head = null; else { Node temp = head.link; head.link = null; head = temp; } }
public void deleteLast() { Node temp = head; if (head == null) System.out.println("The list is empty, nothing to delete."); else if (temp.link == null) head = null; else { while (temp.link.link != null) { temp = temp.link; } temp.link = null; } }
public String toString() { Node temp = head; String result = ""; if (head != null) while(temp != null) { result += temp.info; temp = temp.link; if (temp != null) result +="//"; } return result; }
public void addAtRear (int item) { Node temp = head; Node newNode = new Node(); newNode.info = item; newNode.link = null; if (temp == null) head = newNode; else { while (temp.link != null) { temp = temp.link; } temp.link = newNode; } }