Пример #1
0
        static void Main(string[] args) //main method
        {
            Console.WriteLine("Hash Table");
            MyMapNode <string, int> hashtable = new MyMapNode <string, int>(5);

            hashtable.Display();
            ///*UC1*/
            //MyMapNode<string, string> hashtable = new MyMapNode<string, string>(5); //create MyMapNode class object adn passing key and value and size
            //hashtable.Add("0", "To"); //add key and value
            //hashtable.Add("1", "be");
            //hashtable.Add("2", "or");
            //hashtable.Add("3", "not");
            //hashtable.Add("4", "to");
            //hashtable.Add("5", "be");
            //Console.WriteLine("\nShowing Value using Key using Get Method");
            //Console.WriteLine($"{hashtable.Get("3")}"); //show the specific value from hashtable.
            //hashtable.Remove("5"); //Call Remove method //UC3


            /* UC2:- Ability to find frequency of words in a large paragraph phrase “Paranoids are not
             *       paranoid because they are paranoid but because they keep putting themselves
             *       deliberately into paranoid avoidable situations”
             *       - Use hashcode to find index of the words in the para.
             *       - Create LinkedList for each index and store the words and its frequency.
             *       - Use LinkedList to do the Hash Table Operation.
             *       - To do this create MyMapNode with Key Value Pair and create LinkedList of MyMapNode.
             */

            //MyMapNode<string, int> hashtable = new MyMapNode<string, int>(5);
            string input = "Paranoids are are not paranoid because they are paranoid but because they \n               keep putting themselves deliberately into paranoid avoidable situations\n";

            Console.WriteLine($"Statement is:- {input}");
            hashtable.Display();
            try
            {
                string[] inputArray = input.Split(); // split input statement using Split method

                foreach (string word in inputArray)  //itterat word in inputArray
                {
                    if (hashtable.Get(word) == 0)
                    {
                        hashtable.Add(word, 1); //Add ing key and value
                    }
                    else
                    {
                        int value = hashtable.Get(word) + 1; //add 1
                        hashtable.Set(word, value);          //set word and value
                    }
                }
                string[] newInputArray = inputArray.Distinct().ToArray(); //Unique value store not reapeat value
                foreach (var word in newInputArray)
                {
                    Console.WriteLine("Frequency of Word ccurrence :- \"" + word + "\" is :- " + hashtable.Get(word)); //print word and count
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            /* UC3:- Remove avoidable word from the phrase “Paranoids are not paranoid because they are paranoid but
             *       because they keep putting themselves deliberately into paranoid avoidable situations”
             *       - Use LinkedList to do the Hash Table Operation like here the removal of word avoidable.
             *       - To do this create MyMapNode with Key Value Pair and create LinkedList of MyMapNode.
             */
            hashtable.Remove("avoidable");

            Console.ReadLine();
        }