Exemplo n.º 1
0
        public void Insert(string word)
        {
            TriesNode current = root;

            for (int i = 0; i < word.Length; i++)
            {
                char      ch = word[i];
                TriesNode node;
                current.map.TryGetValue(ch, out node);
                if (node == null)
                {
                    node = new TriesNode();
                    current.map.Add(ch, node);
                }
                current = node;
                Console.WriteLine("End Of The Word:" + current.endOfWord);
            }
            current.endOfWord = true;
        }
Exemplo n.º 2
0
        public void InsertRecUtil(TriesNode current, string word, int index)
        {
            if (index == word.Length)
            {
                current.endOfWord = true;
                return;
            }
            char      ch = word[index];
            TriesNode node;

            current.map.TryGetValue(ch, out node);

            if (node == null)
            {
                node = new TriesNode();
                current.map.Add(ch, node);
            }
            Console.WriteLine("End Of The Word:" + node.endOfWord);

            InsertRecUtil(node, word, index + 1);
        }
Exemplo n.º 3
0
 public Tries()
 {
     root = new TriesNode();
 }