Table 1: Sample Stack Operations
Stack Operation | Stack Contents | Return Value |
---|---|---|
s.isEmpty() | [] | True |
s.push(4) | [4] | |
s.push(‘dog’) | [4,‘dog’] | |
s.peek() | [4,‘dog’] | ‘dog’ |
s.push(True) | [4,‘dog’,True] | |
s.size() | [4,‘dog’,True] | 3 |
s.isEmpty() | [4,‘dog’,True] | False |
s.push(8.4) | [4,‘dog’,True,8.4] | |
s.pop() | [4,‘dog’,True] | 8.4 |
s.pop() | [4,‘dog’] | True |
s.size() | [4,‘dog’] | 2 |
栈应用:
1.括号匹配
2.符号匹配
3.进制转换
4.前后中缀表达式转换