Git Product home page Git Product logo

Comments (5)

hongyangliao avatar hongyangliao commented on July 24, 2024

哨兵节点可以简化代码

from algorithm007-class02.

Zts0hg avatar Zts0hg commented on July 24, 2024

我之前对链表也有些懵。我自己是在建立结点,然后结点交换来交换去的时候容易混乱。
之后总结了一下,链表的题,需要注意是否需建立这三类指针/结点:

  1. 哨兵结点,dummy,为了方便返回结果。
  2. 前继/当前结点, prev / curr,主要出现在需要对链表进行局部位置反转的题,反转时需要知道前继结点的位置,所以需要一个指针记录
  3. 临时结点, temp,交换/增加结点所需,如插入时需要先保存下一个结点的位置,即temp->next = curr->next, 然后将上一结点的next指针指向temp,即curr->next = temp

仅供参考。

from algorithm007-class02.

HelloZJW avatar HelloZJW commented on July 24, 2024

我之前对链表也有些懵。我自己是在建立结点,然后结点交换来交换去的时候容易混乱。
之后总结了一下,链表的题,需要注意是否需建立这三类指针/结点:

  1. 哨兵结点,dummy,为了方便返回结果。
  2. 前继/当前结点, prev / curr,主要出现在需要对链表进行局部位置反转的题,反转时需要知道前继结点的位置,所以需要一个指针记录
  3. 临时结点, temp,交换/增加结点所需,如插入时需要先保存下一个结点的位置,即temp->next = curr->next, 然后将上一结点的next指针指向temp,即curr->next = temp

仅供参考。

总结的很好。有收获

from algorithm007-class02.

cyccactus avatar cyccactus commented on July 24, 2024

碰上双向循环链表必须得小心。前驱节点和后驱节点,很可能会漏,就会造成异常。
链表的哨兵节点很精妙的解法

from algorithm007-class02.

cmnoe avatar cmnoe commented on July 24, 2024

学习了

from algorithm007-class02.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.