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

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