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