张德发 發表於 2021-12-13 22:19:00

链表

<pre><code class="language-js">//JS没有链表,可以用object 模拟链表

const a = { val: 'a'};
const b = { val: 'b'};
const c = { val: 'c'};
const d = { val: 'd'};
a.next = b;
b.next = c;
c.next = d;

//遍历链表
let p = a;
while (p) {
    console.log(p.val);
    p = p.next;
}

//插入
const e = { val: 'e'}
c.next = e;
e.next = d;
</code></pre><br><br>
来源:https://www.cnblogs.com/knightoffz/p/15685569.html
頁: [1]
查看完整版本: 链表