Beispiel #1
0
 public void Remove(string wordToBeRemoved)
 {
     try
     {
         int  wordNo    = new int();
         int  removalNo = 0;
         bool wordFound = false;
         foreach (string word in words)
         {
             if (word == wordToBeRemoved)
             {
                 myMapNodeObj.Remove(wordNo);
                 wordFound = true;
                 removalNo++;
             }
             wordNo++;
         }
         if (wordFound == true)
         {
             Console.WriteLine($"{wordToBeRemoved} removed at {removalNo} places");
         }
         else
         {
             throw new MyParaException(MyParaException.ExceptionType.NO_SUCH_WORD, "No such word in given para/sentence");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Beispiel #2
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 #3
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");
         }
     }
 }
Beispiel #4
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();
        }