1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-06-16 18:10:13 +08:00

Merge pull request #2415 from CoisiniAKAM/main

Update linkedlist-source-code.md
This commit is contained in:
Guide 2024-06-27 14:53:22 +08:00 committed by GitHub
commit 132ef6acbd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -151,8 +151,9 @@ void linkBefore(E e, Node<E> succ) {
final Node<E> newNode = new Node<>(pred, e, succ);
// 将 succ 节点前驱引用 prev 指向新节点
succ.prev = newNode;
// 判断尾节点是否为空,为空表示当前链表还没有节点
// 判断前驱节点是否为空,为空表示 succ 是第一个节点
if (pred == null)
// 新节点成为第一个节点
first = newNode;
else
// succ 节点前驱的后继引用指向新节点