Stack

Linear data structure.

First In Last Out.

push: O(1)  pop: O(1)  peek: O(1)

In Java, there is a Stack class.

A more complete and consistent set of LIFO stack operations is provided by the Deque interface and its implementations, which should be used in preference to this class. For example:
Deque<Integer> stack = new ArrayDeque<Integer>();

 

Implementation of Stack

1. Use array

2. Use linked list

 

Example:

Implement stack using queues

 

posted @ 2015-10-25 02:41  树獭君  阅读(113)  评论(0编辑  收藏  举报