225. Implement Stack using Queues

来源:互联网 发布:破特大网络贩枪案 编辑:程序博客网 时间:2024/05/23 19:10
class MyStack {    LinkedList<Integer>  list = new LinkedList<Integer>();    // Push element x onto stack.    public void push(int x) {        list.add(x);    }    // Removes the element on top of the stack.    public void pop() {        if(!list.isEmpty()) {            list.removeLast();        }    }    // Get the top element.    public int top() {       return  list.getLast();    }    // Return whether the stack is empty.    public boolean empty() {        return list.isEmpty();    }}
0 0
原创粉丝点击