Comments (5)
哨兵节点可以简化代码
from algorithm007-class02.
我之前对链表也有些懵。我自己是在建立结点,然后结点交换来交换去的时候容易混乱。
之后总结了一下,链表的题,需要注意是否需建立这三类指针/结点:
- 哨兵结点,dummy,为了方便返回结果。
- 前继/当前结点, prev / curr,主要出现在需要对链表进行局部位置反转的题,反转时需要知道前继结点的位置,所以需要一个指针记录
- 临时结点, temp,交换/增加结点所需,如插入时需要先保存下一个结点的位置,即temp->next = curr->next, 然后将上一结点的next指针指向temp,即curr->next = temp
仅供参考。
from algorithm007-class02.
我之前对链表也有些懵。我自己是在建立结点,然后结点交换来交换去的时候容易混乱。
之后总结了一下,链表的题,需要注意是否需建立这三类指针/结点:
- 哨兵结点,dummy,为了方便返回结果。
- 前继/当前结点, prev / curr,主要出现在需要对链表进行局部位置反转的题,反转时需要知道前继结点的位置,所以需要一个指针记录
- 临时结点, temp,交换/增加结点所需,如插入时需要先保存下一个结点的位置,即temp->next = curr->next, 然后将上一结点的next指针指向temp,即curr->next = temp
仅供参考。
总结的很好。有收获
from algorithm007-class02.
碰上双向循环链表必须得小心。前驱节点和后驱节点,很可能会漏,就会造成异常。
链表的哨兵节点很精妙的解法
from algorithm007-class02.
学习了
from algorithm007-class02.
Related Issues (20)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from algorithm007-class02.