对于 `doubly-linked-list.js` 中的 insertBefore 和 insertAfter 的 While 条件有点困惑

作者: lchtao26创建于 2021年2月8日更新于 2023年10月13日

~/computer-science-in-JavaScript/src/data-structures/doubly-linked-list/doubly-linked-list.js

insertBefore(data, index) {
            // ...omit other lines util here
            // line 183
            while ((current.next !== null) && (i < index)) {
                current = current.next;
                i++;
            }
        }

insertAfter(data, index) { // ...omit other lines util here // line 259 while ((current !== null) && (i < index)) { current = current.next; i++; } }

我对 line 183 和 259 之间的 while 条件的区别感到困惑,并且在 node 中对 insertAfter 方法进行了测试:

内容来源: humanwhocodes/computer-science-in-javascript