Why does this code , reversing the linked list, override head’s.next but the fast and slow pointers algorithm doesn’t?
the 2nd while loop only has the head and head.next is None
`front, back = head, None
while front:
temp = front.next
front.next = back
back = front
front = temp
walker = head
while walker:
print(“Next”)
walker = walker.next`
Here heads.next is retained and goes further even though fast is also pointing to head and eventually makes fast.next = None.
slow, fast = head, head
while fast is not None and fast.next is not None:
slow = slow.next
fast = fast.next.next
slow is now pointing to the middle node
head_second_half = reverse(slow) # reverse the second half
head_first_half = head
Thank you!