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
Published at
2026-10-08 18:07:26 UTCEvent JSON
{
"id": "7777cfffdeeb4c954722a0b09cf2eed4dd3d4bee19f1eaacaebaba473cce6845",
"pubkey": "e68a0856e90d9997b1f721e905249896412dd570399a987b2e8fd5e7fcfe2279",
"created_at": 1791482846,
"kind": 1,
"tags": [
[
"t",
"ll008"
]
],
"content": "Learn: The dummy node trick\n\nWhen you build a linked list by appending, the first node is a special case: there is no tail yet.\n\nA dummy node removes that special case. Start with a fake node, append after it, and at the end return dummy.Next.\n\n```csharp\nvar dummy = new Node(0, null);\nNode tail = dummy;\nforeach (int v in new[] { 5, 6, 7 }) tail = tail.Next = new Node(v, null);\nPrint(dummy.Next);\n```\n\nIt prints 5 → 6 → 7. The dummy's own value is never used.\n\n#ll008 · LL-008-N",
"sig": "662fb131a240be4e42c1f9e249e96256e03abe9c1ae656e27db636dd0899ebb529eeccb2f31a0ec853ed2e28a20d2afb8c9069f4bf560d076d0b89a5bcb40c78"
}