码迷,mamicode.com
首页 > 其他好文 > 详细

Stack

时间:2018-02-20 23:35:44      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:interface   false   log   imp   empty   stat   linked   integer   pre   

Stack: LIFO, 

the Stack is a deprecated interface we should use Deque interface. The implementation can use LinkedList or array

push, pop, peek, size(), isEmpty()

public static void main(String[] args){
    Deque<Integer> stack = new LinkedList<>() ;
    stack.push(5);
    stack.push(3);
    System.out.println(stack.size()); //2
    System.out.println(stack.pop()); //3
    System.out.println(stack.peek()); //5
    System.out.println(stack.isEmpty()); //false
    System.out.println(stack.pop()); //5
    System.out.println(stack.isEmpty()); //true
    
}

 

Stack

标签:interface   false   log   imp   empty   stat   linked   integer   pre   

原文地址:https://www.cnblogs.com/davidnyc/p/8455975.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!