Reverse a stretch, lose a node.
transcript
This code flips a stretch. It runs. It returns a list. But a node has vanished. Watch the arrows.
Flip positions two to four. Ten is the node before the stretch. The loop turns three arrows. The stretch has three nodes.
Link ten to forty. Stop there. Twenty still points at null. Nothing leads to fifty. The loop alone leaves two loose ends.
Four nodes are kept. One node is lost for good. On a long chain, it loses thousands. Count the nodes before and after.
Point twenty at curr. Now twenty leads to fifty. The chain reads ten, forty, thirty, twenty, fifty. Both links are needed.
A stretch has two loose ends. Before leads to the new first node. The old first node leads on. Test with a node after the stretch. Run a test with a node after the stretch.
Link both ends. Count your nodes. Try it in the sandbox. Full breakdown in the lecture.