Join Nostr
2026-10-08 18:07:26 UTC

codementor on Nostr: Learn: The dummy node trick When you build a linked list by appending, the first node ...

Learn: The dummy node trick

When you build a linked list by appending, the first node is a special case: there is no tail yet.

A dummy node removes that special case. Start with a fake node, append after it, and at the end return dummy.Next.

```csharp
var dummy = new Node(0, null);
Node tail = dummy;
foreach (int v in new[] { 5, 6, 7 }) tail = tail.Next = new Node(v, null);
Print(dummy.Next);
```

It prints 5 → 6 → 7. The dummy's own value is never used.

#ll008 · LL-008-N