Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!WELCOME TO HASHTABLE");
            Console.WriteLine("Hash table demo"); //() []
            MyMapNode <string, string> hash = new MyMapNode <string, string>(5);

            hash.Add("0", "To be or not to be");
            hash.frequencyOfWords("0");
            hash.Add("1", "A random paragraph can also be an excellent way for a writer to tackle writers' block. Writing block can often happen due to being stuck with a current project that the writer is trying to complete. By inserting a completely random paragraph from which to begin, it can take down some of the issues that may have been causing the writers' block in the first place.");
            hash.frequencyOfWords("1");

            string paragraph = "A random paragraph can also be an excellent way for a writer to tackle writers' block. Writing block can often happen due to being stuck with a current project that the writer is trying to complete. By inserting a completely random paragraph from which to begin, it can take down some of the issues that may have been causing the writers' block in the first place.";

            string[] para = paragraph.Split(" ");
            MyMapNode <int, string> hash1 = new MyMapNode <int, string>(para.Length);
            int key = 0;

            foreach (string word in para)
            {
                hash1.Add(key, word);
                key++;
            }

            hash.Remove(hash1, "avoidable");
        }
Beispiel #2
0
 /// <summary>
 /// UC 2 : Adds the splitPhrase into the map.
 /// </summary>
 /// <param name="splitPhrase">The split phrase.</param>
 /// <param name="mapNode">The map node.</param>
 public static void AddSplitPhraseIntoMap(string[] splitPhrase, MyMapNode <string, string> mapNode)
 {
     Console.WriteLine("Adding KeyValue pair");
     for (int i = 0; i < splitPhrase.Length; i++)
     {
         mapNode.Add($"{i}", splitPhrase[i]);
     }
 }
Beispiel #3
0
 public MyParagraph(string sentence)
 {
     words        = sentence.Split(' ');
     myMapNodeObj = new MyMapNode <int, string>(words.Length);
     foreach (string word in words)
     {
         myMapNodeObj.Add(keyNo, word);
         keyNo++;
     }
 }
Beispiel #4
0
 public void Remove(MyMapNode <int, string> hash, string word)
 {
     for (int key = 0; key < hash.size; key++)
     {
         if (hash.Get(key).Equals(word))
         {
             hash.Remove(key);
             Console.WriteLine("Removed " + word + " from paragraph");
         }
     }
 }
 public void Frequency(MyMapNode <int, string> hash)
 {
     for (int key = 0; key < hash.size; key++)
     {
         frequency.TryAdd(hash.Get(key).ToLower(), 0);
         frequency[hash.Get(key).ToLower()]++;
     }
     foreach (KeyValuePair <string, int> item in frequency)
     {
         Console.WriteLine($"frequency of word '{item.Key}' is {item.Value}");
     }
 }
Beispiel #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the phrase:");
            string phrase = "Paranoids are not paranoid because they are paranoid but because they keep putting themselves deliberately into paranoid avoidable situations";

            string[] splitPhrase = phrase.Split(' ');
            MyMapNode <string, string> mapNode = new MyMapNode <string, string>(splitPhrase.Length);

            AddSplitPhraseIntoMap(splitPhrase, mapNode);
            Console.WriteLine("Frequency before removal:");
            mapNode.GetFrequencyOf("paranoid");
            mapNode.Remove("paranoid");
            Console.WriteLine("Frequency after removal:");
            mapNode.GetFrequencyOf("paranoid");
            mapNode.Display();
            Console.ReadLine();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Hash Table Problem!");
            string paragraph = "Paranoids are not paranoid because they are paranoid but because they keep putting themselves deliberately into paranoid avoidable situations";

            string[] para = paragraph.Split(" ");
            MyMapNode <int, string> hash = new MyMapNode <int, string>(para.Length);
            int key = 0;

            foreach (string word in para)
            {
                hash.Add(key, word);
                key++;
            }
            Operation operation = new Operation();

            operation.Frequency(hash);
        }