栈.md

栈(stack)又名后进先出表,它是一种运算受限的线性表。其限制是仅允许在表的一端进行插入和删除运算。这一端被称为栈顶,相对地,把另一端称为栈底。

栈的经典应用——逆波兰表达式法

逆波兰表达式是一种利用栈来进行运算的数学表达式

数字不变,如果遇到符号就计算

用栈解决CPU运算的问题

作业

栈实现逆波兰表达式,要求,运用队列和栈同时完成

JVM内存栈

面试

Java中的Stack是通过Vector来实现的,这种设计被认为是不良的设计,说说你的看法?

使用Stack的时候就会调用大量的Vector里面的函数,Stack暴露了Vector的所有方法,Vector里面会有很多不符合Stack的操作,比如Vector中有下方add方法,是public的,在Stack中是可以调用的,即栈可以在固定位置添加元素(随意添加),这是不符合栈的特性了:
public void add(int index, E element)

Stack -> Vector -> AbstractList

https://leetcode.com/problems/valid-parentheses/

https://leetcode.com/problems/evaluate-reverse-polish-notation/

https://leetcode.com/problems/implement-stack-using-queues/

https://leetcode.com/problems/decode-string/

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

扫一扫,分享到微信

微信分享二维码
  • Copyrights © 2023-2025 Annie
  • Visitors: | Views:

嘿嘿 请我吃小蛋糕吧~

支付宝
微信