|
2 | 2 |
|
3 | 3 | importjava.util.LinkedList;
|
4 | 4 | importjava.util.Queue;
|
5 |
| -/** |
6 |
| - * 225. Implement Stack using Queues |
7 |
| - * |
8 |
| - * Implement the following operations of a stack using queues. |
9 |
| -
|
10 |
| - push(x) -- Push element x onto stack. |
11 |
| - pop() -- Removes the element on top of the stack. |
12 |
| - top() -- Get the top element. |
13 |
| - empty() -- Return whether the stack is empty. |
14 |
| -
|
15 |
| - Notes: |
16 |
| - You must use only standard operations of a queue -- which means only push to back, peek/pop from front, size, and is empty operations are valid. |
17 |
| - Depending on your language, queue may not be supported natively. You may simulate a queue by using a list or deque (double-ended queue), as long as you use only standard operations of a queue. |
18 |
| - You may assume that all operations are valid (for example, no pop or top operations will be called on an empty stack). |
19 |
| - Update (2015-06-11): |
20 |
| - The class name of the Java function had been updated to MyStack instead of Stack.*/ |
21 | 5 |
|
22 | 6 | publicclass_225 {
|
23 | 7 |
|
|