Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var trie = new Trie();

            trie.Insert("abh");
            trie.Insert("abc");

            Console.WriteLine(trie.Search("abh"));
            Console.WriteLine(trie.Search("abc"));
            Console.WriteLine(trie.Search("a"));
            Console.WriteLine(trie.Search("abhi"));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Trie trie = new Trie();

            trie.Insert("apple");
            Console.WriteLine(trie.Search("apple"));
            Console.WriteLine(trie.Search("app"));
            Console.WriteLine(trie.StartsWith("app"));

            trie.Insert("app");
            Console.WriteLine(trie.Search("app"));
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Trie t = new Trie();

            t.Add("apple");
            t.Add("anar");

            t.Add("Mango");

            Console.WriteLine("is 'anar' there? " + t.Search("anar"));
            Console.WriteLine("is 'App' there? " + t.Search("App"));
            Console.ReadKey();
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            Trie t = new Trie();

            Console.WriteLine(string.Format("t.search(fubar): {0}", t.Search("fubar")));
            Console.WriteLine(string.Format("t.StartsWith(fubar): {0}", t.StartsWith("fubar")));
            Console.WriteLine(string.Format("t.Insert(a)"));
            t.Insert("a");
            Console.WriteLine(string.Format("t.search(a): {0}", t.Search("a")));
            Console.WriteLine(string.Format("t.StartsWith(a): {0}", t.StartsWith("a")));
            Console.WriteLine(string.Format("t.StartsWith(fub): {0}", t.StartsWith("fub")));

            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Trie trie = new Trie();

            trie.Insert("hello");
            //Console.ReadLine();
            //trie.Search("apple");
            Console.WriteLine("{0}", trie.Search("hello"));
            Console.ReadLine();
            Console.WriteLine("{0}", trie.Search("hell"));
            Console.ReadLine();
            Console.WriteLine("{0}", trie.Search("helloa"));
            Console.ReadLine();
            trie.Search("app");
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Trie trie = new Trie();

            trie.Insert("cat");
            trie.Insert("cap");
            trie.Insert("bat");
            trie.Insert("tre");
            trie.Insert("ball");
            trie.Insert("hat");
            trie.Insert("map");
            trie.Insert("mall");

            Console.WriteLine(trie.Search("mallp"));
            Console.WriteLine(trie.Search(""));
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            var trie = new Trie();

            var keys          = ReadFile(filePath1);
            var alternateKeys = ReadFile(filePath2);

            foreach (var s in keys)
            {
                trie.Insert(s);
            }

            foreach (var s in keys)
            {
                Console.WriteLine(trie.Search(s) ? "Found: " + s : "Did not find: " + s);
            }

            foreach (var s in alternateKeys)
            {
                Console.WriteLine(trie.Search(s) ? "Found: " + s : "Did not find: " + s);
            }
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            Trie obj = new Trie();

            obj.Insert("word");
            bool param_2 = obj.Search("word");

            Console.WriteLine("Trie {0}", param_2);
            bool param_3 = obj.StartsWith("prefix");

            Console.WriteLine("Trie {0}", param_3);
            bool param_4 = obj.StartsWith("wor");

            Console.WriteLine("Trie {0}", param_4);
        }
        static void Main(string[] args)
        {
            // Build out our trie
            string[] words = { "apple", "ape", "grape", "grapple", "these", "their", "there" };

            Trie trie = new Trie();

            foreach (string word in words)
            {
                trie.Insert(word);
            }

            // Search for some values
            Console.WriteLine("Trie contains the full word 'these': " + trie.Search("these"));
            Console.WriteLine("Trie contains the full word 'the': " + trie.Search("the"));
            Console.WriteLine("Trie contains the full word  apple': " + trie.Search("apple"));

            Console.WriteLine("Trie contains 'the': " + trie.StartsWith("the"));
            Console.WriteLine("Trie contains 'grap': " + trie.StartsWith("grap"));
            Console.WriteLine("Trie contains 'pe': " + trie.StartsWith("pe"));

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Trie!");
            Console.WriteLine("-----");

            Console.WriteLine("Enter the number of strings to be entered in the trie");
            try
            {
                TrieNode root        = null;
                Trie     trie        = null;
                int      noOfStrings = int.Parse(Console.ReadLine());
                for (int i = 0; i < noOfStrings; i++)
                {
                    Console.WriteLine("Enter the string");
                    String input = Console.ReadLine();
                    trie = new Trie();
                    root = trie.Insert(input);
                }
                int choice = 0;
                do
                {
                    Console.WriteLine("Enter the string to be searched");
                    String word = Console.ReadLine();
                    trie.Search(root, word);
                    Console.WriteLine("Enter 1 to continue search");
                    try
                    {
                        choice = int.Parse(Console.ReadLine());
                    } catch (Exception exception) {
                        Console.WriteLine("Thrown exception is " + exception.Message);
                    }
                } while (choice != 0);
            }
            catch (Exception exception) {
                Console.WriteLine("Exception thrown is " + exception.Message);
            }


            Console.ReadLine();
        }
Exemplo n.º 11
0
        private void button2_Click(object sender, EventArgs e)
        {
            var v = trie.Search(textBox1.Text);

            MessageBox.Show(v.ToString());
        }