一段代码让你彻底搞清楚队列和栈的方法

    public static void main(String[] args) {
        Deque<Integer> q1=new LinkedList();
        q1.offer(1);
        q1.offer(2);
        q1.offer(3);
        q1.offer(4);
        q1.offer(5);
        System.out.println(q1.poll());
        System.out.println(q1.pop());
        System.out.println(q1.peek());
        q1.push(6);
        System.out.println(q1.poll());
    }
结果:
1
2
3
6

队列是尾进头出,队列的头对应栈的顶 


版权声明:本文为weixin_45241622原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。