Created
May 19, 2025 08:05
-
-
Save paratechnical/f63009442e02ffe62e20b922bdb9237a to your computer and use it in GitHub Desktop.
C# Prefix Tree Node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node | |
| { | |
| public char Char; | |
| public bool AWordEndsHere; | |
| public List<Node> Subtree; | |
| public Node(char c) | |
| { | |
| Char = c; | |
| Subtree = new List<Node>(); | |
| } | |
| public Node(char c, bool wordends):this(c) | |
| { | |
| AWordEndsHere = wordends; | |
| } | |
| public Node GetChild(char c) | |
| { | |
| if (Subtree.Count != 0) | |
| foreach (var node in Subtree) | |
| if (node.Char == c) | |
| return node; | |
| return null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment