GithubHelp home page GithubHelp logo

06链表逆置 about duyi-webalgorithm HOT 4 OPEN

wangjieCode avatar wangjieCode commented on September 28, 2024
06链表逆置

from duyi-webalgorithm.

Comments (4)

github15238484509 avatar github15238484509 commented on September 28, 2024 1

在链表长度为2的时候,会形成环形

先谢谢你,不然我也没发现

from duyi-webalgorithm.

github15238484509 avatar github15238484509 commented on September 28, 2024

在链表长度为2的时候,会形成环形 baby 我来帮你实现了

function Node(value) {
this.value = value
this.next = null
}
var a = new Node("a")
var b = new Node("b")
var c = new Node("c")
var d = new Node("d")
var e = new Node("e")
var f = new Node("f")

function bindNode(...arg) {
for (let i = 0; i < arg.length - 1; i++) {
var cur = arg[i]
cur.next = arg[i + 1]
}
}
bindNode(a, b, c, d, e, f)

function reverse(node) {
if (node === null || node.next === null) {
return node;
}
if (node.next.next === null) {
node.next.next = node
var last = node.next//返回最后一位
node.next = null//吧最后一位的上一位设置成空
return last
} else {
var result = reverse(node.next)//result 一直为最后一位
node.next.next = node// 这句话对应最后一次循环 吧倒数第二位的next的指向倒数三位
node.next = null// 这句话对应最后一次循环 吧 倒数第三为的next 指向null
return result
}
}
console.log(reverse(a));

from duyi-webalgorithm.

shenxiang11 avatar shenxiang11 commented on September 28, 2024

空链表也不对呀,课程开头也说了:“考算法题的时候,一分没有必须有严谨性判断”

from duyi-webalgorithm.

yjisme avatar yjisme commented on September 28, 2024

感谢提醒,bug已修复到对应分支,请重新拉取

from duyi-webalgorithm.

Related Issues (3)

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.