class MyStack {
LinkedList<Integer> q = new LinkedList<>();
public void push(int x) {
q.add(x);
for(int i = 0; i < q.size()-1; i++){
q.add(q.remove());
}
}//0123
// Removes the element from in front of queue.
public void pop() {
q.remove();
}
// Get the front element.
public int top() {
return q.getFirst();
}
// Return whether the queue is empty.
public boolean empty() {
return q.isEmpty();
}
}
没有评论:
发表评论