linked list must end with 'null'
We need to put 'null' to end of linked list. otherwise wen we want to get last item in the linked list, it will be undefined. And this situation inconsistent with object literal definition of linked list above.
This commit is contained in:
parent
d5195b5d59
commit
95495bd5dc
1 changed files with 1 additions and 0 deletions
|
@ -459,6 +459,7 @@ let list = { value: 1 };
|
||||||
list.next = { value: 2 };
|
list.next = { value: 2 };
|
||||||
list.next.next = { value: 3 };
|
list.next.next = { value: 3 };
|
||||||
list.next.next.next = { value: 4 };
|
list.next.next.next = { value: 4 };
|
||||||
|
list.next.next.next.next = null;
|
||||||
```
|
```
|
||||||
|
|
||||||
Here we can even more clearer see that there are multiple objects, each one has the `value` and `next` pointing to the neighbour. The `list` variable is the first object in the chain, so following `next` pointers from it we can reach any element.
|
Here we can even more clearer see that there are multiple objects, each one has the `value` and `next` pointing to the neighbour. The `list` variable is the first object in the chain, so following `next` pointers from it we can reach any element.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue