Open ahasusie opened 5 years ago
two pointers
template:
Always examine if the node is null before you call the next field. Getting the next node of a null node will cause the null-pointer error. For example, before we run fast = fast.next.next, we need to examine both fast and fast.next is not null.
Carefully define the end conditions of your loop.
traversal insert/delete search detect loop sort reverse double linked list
practice: 21, 206, 19, 141, 142, LinkedList.py
common mistakes:
cur = cur.next
next = prev = None
cur.next = None
for i in range(1, N)
while cur:
vswhile cur.next:
cur.next
then must judge ifcur
is none.cur.next.next
then must judge ifcur.next
is nonedummy node: