思路:将新存入队列的值,放在队列最前面的地方(即通过一个for循环将除了最新插入的数据外全部取出插入一遍),
class MyStack {
private Queue<Integer> b;
public MyStack() {
b = new LinkedList<Integer>();
}
public void push(int x) {
int n = b.size();
for(i=0;i<n;i++){
b.offer(b.poll());
}
}
public int pop() {
return b.poll();
}
public int top() {
return b.peek();
}
public boolean empty() {
return b.isEmpty();
}
}