Example #1
0
 public void removeFront() throws StackEmptyException {
   if (empty()) {
     throw new StackEmptyException("Stack is Empty");
   } else {
     head.setNext(head.getNext());
     size--;
   }
 }
Example #2
0
 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++;
   }
 }
Example #3
0
  public String toString(T data) {
    String s = "[ ";
    while (head.getNext() != null) {
      s += (data + ", ");
    }

    return s;
  }
Example #4
0
 public void insertBack(T data) {
   LLNode<T> nn = new LLNode<T>(data);
   if (empty()) {
     tail.setNext(nn);
     tail = nn;
     size++;
   }
 }
Example #5
0
 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;
 }
Example #6
0
 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;
   }
 }