public void addToEnd(Object element) { LinearNode newNode = new LinearNode(element); if (front == null) front = newNode; else { LinearNode temp = front; while (temp.getNext() != null) temp = temp.getNext(); temp.setNext(newNode); } }
public void removeLast() { if (front != null) { LinearNode temp = front; LinearNode prev = null; while (temp.getNext() != null) { prev = temp; temp = temp.getNext(); } if (prev == null) front = null; else prev.setNext(null); } }
public void removeNth(int n) { if (front != null && n == 0) front = front.getNext(); else { LinearNode temp = front; int i = 1; while (i < n && temp != null) { temp = temp.getNext(); i++; } if (temp != null && temp.getNext() != null) temp.setNext(temp.getNext().getNext()); } }