// CSE 143, Autumn 2013 // A LinkedIntList object stores a list of integers using a series of linked // node objects. We will implement the same methods as ArrayIntList. public class LinkedIntList { private ListNode front; // refers to first node in list (null if empty) // Constructs a new empty list. public LinkedIntList() { front = null; } // Adds the given value to the end of this list. public void add(int value) { if (front == null) { // empty list front = new ListNode(value); } else { // non-empty list; walk to last node ListNode current = front; while(current.next != null) { current = current.next; } // add new node at end of list current.next = new ListNode(value); } } // Returns the element at the specified index from the list. // Precondition: 0 <= index < size public int get(int index) { ListNode current = front; for(int i = 0; i < index; i++) { current = current.next; } return current.data; } }