老师,我发现你实现的stack的pop是removeFirst

来源:4-6 使用链表实现栈

json7

2020-06-01

老师,我发现你用linkedList实现的stack的pop是removeFirst,应该是removeLast吧,stack先进后出,用removeLast,10万数据的时候linkedList的性能就差好多了

写回答

1回答

liuyubobobo

2020-06-02

课程中实现的栈,栈顶在 first。所以 push 和 pop 操作都在 first。栈是在同一端进出。

可以再仔细看一下课程代码:https://git.imooc.com/coding-207/coding-207/src/master/04-Linked-List/06-Implement-Stack-in-LinkedList/src/LinkedListStack.java


是的,如果数据规模大了,LinkedList 性能不优。我写过一篇公众号文章,可以参考:https://mp.weixin.qq.com/s?__biz=MzU4NTIxODYwMQ==&mid=2247485646&idx=1&sn=044c6359c49f65935333e6e6c6366f91&chksm=fd8ca788cafb2e9e2fd35d6afc16103dfa9598b255cdd716f1f5b9ea3b210daad591a1abde42&token=2011413782&lang=zh_CN#rd


继续加油!:)

0
0

玩转数据结构

动态数组/栈/队列/链表/BST/堆/线段树/Trie/并查集/AVL/红黑树…

6221 学习 · 1705 问题

查看课程