LogFAQs > #970091300

LurkerFAQs, Active DB, DB1, DB2, DB3, DB4, DB5, DB6, DB7, DB8, DB9, DB10, Database 11 ( 12.2022-11.2023 ), DB12, Clear
Topic List
Page List: 1
TopicI know what a Linked List is
Tyranthraxus
12/11/22 4:55:17 PM
#27:


AlephZero posted...
The "best" way to do it is to use two pointers, a fast one and a slow one. In a loop move the fast one forward two nodes and the slow one forward one node. If the fast one reaches the end of the list there is no loop. If at any time they both point to the same node there is a loop.

Why would you do this?

Why not just reference the pointer to the head?

The method you're describing is used to find the middle of a linked list. Once the fast pointer has reached the end, you take whatever is in the slow pointer.

---
It says right here in Matthew 16:4 "Jesus doth not need a giant Mecha."
https://i.imgur.com/dQgC4kv.jpg
... Copied to Clipboard!
Topic List
Page List: 1