Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to hashtable demo");
            MyMapNode <string, string> hash = new MyMapNode <string, string>(5);

            hash.Add("0", "Paranoids");
            hash.Add("1", "are");
            hash.Add("2", "not");
            hash.Add("3", "paranoids");
            hash.Add("4", "beacuse");
            hash.Add("5", "they");
            hash.Add("6", "are");
            hash.Add("7", "paranoid");
            hash.Add("8", "but");
            hash.Add("9", "because");
            hash.Add("10", "they");
            hash.Add("11", "keep");
            hash.Add("12", "putting");
            hash.Add("13", "themselves");
            hash.Add("14", "deliberately");
            hash.Add("15", "into");
            hash.Add("16", "paranoid");
            hash.Add("17", "avoidable");
            hash.Add("18", "situations");
            hash.GetFrequency("avoidable");
            hash.RemoveValue("avoidable");
            hash.GetFrequency("avoidable");
            Console.ReadKey();
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Hash Table implementation");
            MyMapNode <string, string> hash = new MyMapNode <string, string>(5);

            hash.Add("0", "To");
            hash.Add("1", "be");
            hash.Add("2", "or");
            hash.Add("3", "not");
            hash.Add("4", "To");
            hash.Add("5", "be");
            string hash5 = hash.Get("4");

            Console.WriteLine("5th index value:" + hash5);
            string paragraph = "Paranoids are not paranoid because they are paranoid but because they keep putting themselves deliberately into paranoid avoidable situations";

            ///Split converts paragraph  into array of sub strings.
            string[] para = paragraph.Split(" ");
            ///Creating reference of MyMapNode.
            MyMapNode <int, string> hash1 = new MyMapNode <int, string>(para.Length);
            int key = 0;

            ///foreach iterates on paragraph and adds key and value to hash.
            foreach (string word in para)
            {
                hash1.Add(key, word);
                key++;
            }
            Console.WriteLine("\nFrequency :" + hash1.GetFrequency("paranoid"));
            hash1.RemoveValue("avoidable");
            Console.WriteLine("Frequency :" + hash.GetFrequency("avoidable"));
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the sentence");
            string sentence = Console.ReadLine();

            string[] splitMessage           = sentence.Split(" ");
            MyMapNode <string, int> mapNode = new MyMapNode <string, int>(splitMessage.Length);

            for (int i = 0; i < splitMessage.Length; i++)
            {
                mapNode.Add(splitMessage[i], i);
            }
            Console.WriteLine("Enter the word where you require to know the frequency");
            string word = Console.ReadLine();

            mapNode.GetFrequency(word);
            Console.WriteLine("Enter the word that you want to remove");
            string remove = Console.ReadLine();

            mapNode.Remove(remove);
            mapNode.Display();
            Console.ReadLine();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hash table demo");
            MyMapNode <string, string> hash = new MyMapNode <string, string>(5);

            hash.Add("0", "To");
            hash.Add("1", "be");
            hash.Add("2", "or");
            hash.Add("3", "not");
            hash.Add("4", "to");
            hash.Add("5", "be");
            string checkFreq = "be";
            int    freq      = hash.GetFrequency(checkFreq);

            Console.ReadKey();



            Console.WriteLine("Hash table demo");
            MyMapNode <string, string> hash = new MyMapNode <string, string>(5);
            string para = "Paranoids are not paranoid because they are paranoid but because they keep putting themselves deliberately into paranoid avoidable situations";

            string[] paraWords = para.Split(' ');
            int      pLength   = paraWords.Length;

            for (int i = 0; i < pLength; i++)
            {
                hash.Add(Convert.ToString(i), paraWords[i]);
            }
            foreach (string word in paraWords)
            {
                hash.GetFrequency(word);
            }
            Console.ReadKey();



            Console.WriteLine("Hash table demo");
            MyMapNode <string, string> hash = new MyMapNode <string, string>(5);
            string para = "Paranoids are not paranoid because they are paranoid but because they keep putting themselves deliberately into paranoid avoidable situations";

            string[] paraWords = para.Split(' ');
            int      pLength   = paraWords.Length;

            for (int i = 0; i < pLength; i++)
            {
                hash.Add(Convert.ToString(i), paraWords[i]);
            }

            Console.WriteLine("Frequency of 'avoidable' before removal is :" + hash.GetFrequency("avoidable"));
            hash.RemoveValue("avoidable");
            Console.WriteLine("Frequency of 'avoidable' after removal is :" + hash.GetFrequency("avoidable"));
            Console.ReadKey();


            Console.WriteLine("Hello!! Welcome to Binary Search Tree");
            BST <int> bst = new BST <int>();


            bst.Insert(56);
            bst.Insert(30);
            bst.Insert(70);

            bst.DisplayBST(bst.root);


            int[] arr = { 56, 30, 70, 22, 60, 40, 95, 16, 63, 67, 4, 11, 65 };
            for (int i = 0; i < arr.Length; i++)
            {
                bst.Insert(arr[i]);
            }
            bst.DisplayBST(bst.root);
            Console.WriteLine("\n\nSize of BST: " + bst.Size(bst.root));



            bst.Search(60);
            bst.Search(20);
        }