美文网首页
Int Node 与SLList

Int Node 与SLList

作者: 余鹿 | 来源:发表于2017-07-16 18:46 被阅读0次
IntNode——SLList

week02.03 sentinel的出现是为了便于添加,移除节点,sentinel 本身为null

我们可以通过将指针从last 上移除来实现remove操作,但是指针需要移动到last 之前的位置上,而快速寻找这个位置就是需要解决的问题,而last有时指向sentinel有时指向一个real node。

如果想要解决上面的问题可以设置两个sentinel,一个指向item.next一个指向 last.item,  这样的方式使得两个sentinel 组成了一个循环形成了一个sentinel.

cir sentinel

相关文章

网友评论

      本文标题:Int Node 与SLList

      本文链接:https://www.haomeiwen.com/subject/lxatkxtx.html