public void removeFront() throws StackEmptyException { if (empty()) { throw new StackEmptyException("Stack is Empty"); } else { head.setNext(head.getNext()); size--; } }
public void insertFront(T data) { LLNode<T> nn = new LLNode<T>(data); if (empty()) { head = nn; tail = nn; size++; } else { nn.setNext(tail); tail = nn; size++; } }
public String toString(T data) { String s = "[ "; while (head.getNext() != null) { s += (data + ", "); } return s; }
public void insertBack(T data) { LLNode<T> nn = new LLNode<T>(data); if (empty()) { tail.setNext(nn); tail = nn; size++; } }
public void removeSecondLast() { LLNode<T> tmp = new LLNode(); LLNode<T> prev = new LLNode(); tmp.setNext(head.getNext()); while (tmp.getNext() != tail) { prev.getNext(); } prev.setNext(prev.getNext()); tail = prev; }
public void removeBack() throws StackEmptyException { if (empty()) { throw new StackEmptyException("Stack is Empty"); } else { LLNode<T> tmp = new LLNode(); LLNode<T> prev = new LLNode(); tmp.setNext(head); while (tmp.getNext() != tail) { prev.getNext(); } prev.setNext(prev); tail = prev; } }