Originally Posted by
Elysia
If you want to traverse a node and you don't know the end, then you need a temporary pointer which you can use to traverse with. You can do quene->first->next->next->next, but how do you know where the end is? Further, if you actually try to walk further than the end, you try to dereference NULL, which will lead to a crash.
Therefore, we use a temporary variable, assign that to quene->first, and then check if p == NULL (in which case there's only one node in the list, since q->first is the first node and if the first node points to NULL, there is no second node, no node after the first node).