Stack

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<>() ;
System.out.println(stack.size()); //0 empty stack size = 0
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

}

 

posted @ 2018-02-20 23:07  davidnyc  阅读(132)  评论(0编辑  收藏  举报