Exemple #1
0
        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;
        }
Exemple #2
0
            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;
            }
Exemple #3
0
 public Trie()
 {
     this.root      = new BoggleBoardTrieNode();
     this.endSymbol = '*';
 }