Stack
---
What it is?
A stack is a one-ended linear data structures which has two primary operations,namely push and pop ( Last in First out )
Complexity
Example_01_ Brackets
按顺序push
if 当前进栈符号为左括号,then 直接进栈
if 当前入栈符号为右括号,then 检查栈顶是否为对应的reverse bracket
若是,则括号匹配,pop栈顶符号,否则匹配失败,结束程序
重复上述操作直至栈为空,匹配成功,结束程序
源码实现
使用java.util.LinkedList构造链栈
链尾表示栈顶,用addLast实现push,removeLast实现pop
测试结果: