예제 #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;
        }
예제 #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);
        }
예제 #3
0
 public Tries()
 {
     root = new TriesNode();
 }