@Test(expected = NoSuchElementException.class) public void basicTest5() { QueueByTwoStack<String> queue = new QueueByTwoStack(); queue.dequeue(); }
public Item dequeue() { if (isEmpty()) { throw new NoSuchElementException("queue is empty"); } if (!out.isEmpty()) { return out.pop(); } while (!in.isEmpty()) { out.push(in.pop()); } return out.pop(); }
QueueByTwoStack { public Item dequeue() { if (isEmpty()) { throw new NoSuchElementException("queue is empty"); } if (!out.isEmpty()) { return out.pop(); } while (!in.isEmpty()) { out.push(in.pop()); } return out.pop(); } }
QueueByTwoStack { public Item dequeue() { if (isEmpty()) { throw new NoSuchElementException("queue is empty"); } if (!out.isEmpty()) { return out.pop(); } while (!in.isEmpty()) { out.push(in.pop()); } return out.pop(); } QueueByTwoStack(); }
QueueByTwoStack { public Item dequeue() { if (isEmpty()) { throw new NoSuchElementException("queue is empty"); } if (!out.isEmpty()) { return out.pop(); } while (!in.isEmpty()) { out.push(in.pop()); } return out.pop(); } QueueByTwoStack(); int size(); boolean isEmpty(); void enqueue(Item i); Item dequeue(); Item peek(); }
QueueByTwoStack { public Item dequeue() { if (isEmpty()) { throw new NoSuchElementException("queue is empty"); } if (!out.isEmpty()) { return out.pop(); } while (!in.isEmpty()) { out.push(in.pop()); } return out.pop(); } QueueByTwoStack(); int size(); boolean isEmpty(); void enqueue(Item i); Item dequeue(); Item peek();  }