public static void explore(int i, int j, char[,] board, BoggleBoardTrieNode BoggleBoardtrieNode, bool[,] visited, HashSet <string> finalWords) { if (visited[i, j]) { return; } char letter = board[i, j]; if (!BoggleBoardtrieNode.children.ContainsKey(letter)) { return; } visited[i, j] = true; BoggleBoardtrieNode = BoggleBoardtrieNode.children[letter]; if (BoggleBoardtrieNode.children.ContainsKey('*')) { finalWords.Add(BoggleBoardtrieNode.word); } List <int[]> neighbors = getNeighbors(i, j, board); foreach (int[] neighbor in neighbors) { explore(neighbor[0], neighbor[1], board, BoggleBoardtrieNode, visited, finalWords); } visited[i, j] = false; }
public void Add(string str) { BoggleBoardTrieNode node = this.root; for (int i = 0; i < str.Length; i++) { char letter = str[i]; if (!node.children.ContainsKey(letter)) { BoggleBoardTrieNode newNode = new BoggleBoardTrieNode(); node.children.Add(letter, newNode); } node = node.children[letter]; } node.children[this.endSymbol] = null; node.word = str; }
public Trie() { this.root = new BoggleBoardTrieNode(); this.endSymbol = '*'; }