static void Main(string[] args) { Console.WriteLine("============Welcome To Hash Table Program================="); MyMapNode <string, string> hash = new MyMapNode <string, string>(5); hash.Add("0", "To be or not to be"); hash.frequencyOfWords("0"); //Passing paragraph and finding frequency hash.Add("1", "Paranoids are not Paranoids because they are Paranoids but because they keep putting themselves deliberatly into paranoids avoidable situations"); hash.frequencyOfWords("1"); //Delete word from paragraph. string para = "Paranoids are not paranoid because they are paranoid but because they keep putting themselves deliberately into paranoid avoidable situations"; string[] storePara = para.Split(" "); MyMapNode <int, string> hash1 = new MyMapNode <int, string>(storePara.Length); int temp = 0; foreach (string word in storePara) { hash1.Add(temp, word); temp++; } hash.Remove(hash1, "avoidable"); }
static void Main(string[] args) { MyMapNode <string, int> myMapNode = new MyMapNode <string, int>(5); string input = "Paranoids are not paranoid because they are paranoid but because " + "they keep putting themselves deliberately into paranoid avoidable situations"; string[] sample = input.Split(' '); foreach (string s in sample) { int count = 0; foreach (string m in sample) { if (s.Equals(m)) { count++; } } myMapNode.Add(s, count); } myMapNode.Display(); myMapNode.Frequency("paranoid"); myMapNode.RemoveElement("avoidable"); myMapNode.Display(); }
static void Main(string[] args) { Console.WriteLine("Hashtable"); MyMapNode <int, string> hash = new MyMapNode <int, string>(6); Function function = new Function(); //Adds details to //uc1 /* hash.Add(0, "To"); * hash.Add(1, "be"); * hash.Add(2, "or"); * hash.Add(3, "not"); * hash.Add(4, "to"); * hash.Add(5, "be"); * //Calls frequencyOfWord method * function.FrequencyOfWord(hash);*/ //UC2 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(" "); int key = 0; //Loop iterates on paragraph and adds key and value of each substing //To hash foreach (string word in para) { hash.Add(key, word); key++; } //Calls Frequency of word method to print word count function.FrequencyOfWord(hash); Console.ReadKey(); }
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")); }
static void Main(string[] args) { Console.WriteLine("Welcome to HashTable Program"); MyMapNode <int, string> hash = new MyMapNode <int, string>(15);//creating object and Key and value datatype is string and size is 5 //creating a string of sentence string phrase = "Paranoids are not paranoid because they are paranoid but because they keep putting themselves deliberately into paranoid avoidable situations"; //adding values into array string[] words = phrase.Split(' '); //split method is used //split string into substrings int a = 1; foreach (var element in words) { hash.Add(a, element); a++; } int index = 18; string choice = hash.Get(index); // getting the specific value from hashtable. Console.WriteLine("{0}th index values : is {1}", index, choice); int index2 = 15; string choice2 = hash.Get(index2); Console.WriteLine("{0}th index values : is {1}", index2, choice2); hash.Remove(index);//remove 18 index hash.Display(); Console.Read(); }
static void Main(string[] args) { Console.WriteLine("-----Welcome To HashTable Program-----"); MyMapNode <string, int> hash = new MyMapNode <string, int>(5); //creating a string of long sentence string words = "Paranoids are not paranoid because they are paranoid but because they keep putting themselves deliberately into paranoid avoidable situations"; //adding values into array string[] arr = words.Split(' '); //creating a linkedlist to check for duplicates value LinkedList <string> checkForDuplication = new LinkedList <string>(); //iterating loop over the array of sentence words foreach (string element in arr) { int count = 0; //another foreach loop to check if other same element is present //if present counter is incremented foreach (string match in arr) { if (element == match) { count++; //if same element is coming in 2nd time, it will be presnent in linkedlist, so loopwill break and no further counting will be done if (checkForDuplication.Contains(element)) { break; } } } //if element is already there in list, outer loop will be continued and loop will shift to next value //basically only values appearing for 1st time, will be added in linkedlist and added in hash table, so that frequency can be displayed. if (checkForDuplication.Contains(element)) { continue; } //added element in linkedlist checkForDuplication.AddLast(element); //added element and it's frequency in hashtable. hash.Add(element, count); } //getting the specific value from hashtable. int frequency = hash.Get("they"); Console.WriteLine("frequency for they:\t" + frequency); //Displaying all the elements from the linkedlist Console.WriteLine(); Console.WriteLine("Displaying all the key value pairs in hash table"); hash.Display(); Console.Read(); }
static void Main(string[] args) { Console.WriteLine("Hash table demo"); //() [] string paragraph = "Paranoids are not paranoid because they are paranoid but because they keep putting themselves deliberately into paranoid avoidable situations"; para = paragraph.Split(' '); MyMapNode <string, string> hash = new MyMapNode <string, string>(para.Length); int key = 0; foreach (string word in para) { hash.Add(key.ToString(), word); key++; } Console.WriteLine("Index Key Value"); for (int i = 0; i < para.Length; i++) { hash.Display(i.ToString()); } for (int i = 0; i < para.Length; i++) { try { MyMapNode <string, string> .dict.Add(para[i], 0); hash.Frequency(i.ToString(), para); } catch (Exception ex) { Console.WriteLine(ex.Message); } } foreach (KeyValuePair <string, int> x in MyMapNode <string, string> .dict) { Console.WriteLine(x.Key + " " + x.Value); } Console.WriteLine("Index Key Value"); hash.Remove("17"); for (int i = 0; i < para.Length; i++) { hash.Display(i.ToString()); } Console.ReadKey(); }
static void Main(string[] args) { 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.Remove(hash, "avoidable"); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); 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("5"); Console.WriteLine("Element present at 5th index:{0}", hash5); }
static void Main(string[] args) { 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("5"); Console.WriteLine(hash5); hash.Remove("5"); }
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(); }
static void Main(string[] args) { Console.WriteLine("Welcome to Hash Table Program!"); 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"); hash.GetFrequency("be"); MyMapNode<string, string> hash2 = new MyMapNode<string, string>(19); hash2.Add("0", "Paranoid"); hash2.Add("1", "are"); hash2.Add("2", "not"); hash2.Add("3", "paranoid"); hash2.Add("4", "beacuse"); hash2.Add("5", "they"); hash2.Add("6", "are"); hash2.Add("7", "paranoid"); hash2.Add("8", "but"); hash2.Add("9", "because"); hash2.Add("10", "they"); hash2.Add("11", "keep"); hash2.Add("12", "putting"); hash2.Add("13", "themselves"); hash2.Add("14", "deliberately"); hash2.Add("15", "into"); hash2.Add("16", "paranoid"); hash2.Add("17", "avoidable"); hash2.Add("18", "situations"); hash2.GetFrequency("paranoid"); hash2.Remove("17"); hash2.GetFrequency("avoidable"); Console.ReadKey(); }
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); }
static void Main(string[] args) { Console.WriteLine("Welcome to Hash Table"); //Declaring MyMapNode object with data type and size of array in parametrized constructor MyMapNode <string, int> hash = new MyMapNode <string, int>(5); //Adding values in hashtable. //hash.Add("0", "To"); //hash.Add("1", "be"); //hash.Add("2", "or"); //hash.Add("3", "not"); //hash.Add("4", "To"); //hash.Add("5", "be"); //getting the specific value from hashtable. //string hash5 = hash.Get("5"); //Console.WriteLine("5th index value:" + hash5); //creating a string of long sentence string words = "Paranoids are not paranoid because they are paranoid but because they keep putting themselves deliberately into paranoid avoidable situations"; //adding values into array string[] arr = words.Split(" "); //creating a linkedlist to check for duplicates value //if duplicate value is coming inside a array, as previous element(when it was not in list) would already contain total count of same elements //it will be skipped LinkedList <string> checkForDuplication = new LinkedList <string>(); //iterating loop over the array of sentence words foreach (string element in arr) { //count iterator for counting no of times word is coming int count = 0; //another foreach loop to check if other same element is present //if present counter is incremented foreach (string match in arr) { if (element == match) { count++; //if same element is coming in 2nd time, it will be presnent in linkedlist, so loopwill break and no further counting will be done if (checkForDuplication.Contains(element)) { break; } } } //if element is already there in list, outer loop will be continued and loop will shift to next value //basically only values appearing for 1st time, will be added in linkedlist and added in hash table, so that frequency can be displayed. if (checkForDuplication.Contains(element)) { continue; } //added element in linkedlist checkForDuplication.AddLast(element); //added element and it's frequency in hashtable. hash.Add(element, count); } //getting the specific value from hashtable. int frequency = hash.Get("Paranoids"); Console.WriteLine("frequency for Paranoids:\t" + frequency); //Displaying all the elements from the linkedlist Console.WriteLine("****************"); Console.WriteLine("Displaying all the key value pairs in hash table"); hash.Display(); Console.WriteLine("**********************************************"); //removing avoidable word from the hashtable hash.Remove("avoidable"); Console.WriteLine("Word removed from hashtable"); //getting the specific value from hashtable. int removedWordFrequency = hash.Get("avoidable"); Console.WriteLine("frequency for avoidable:\t" + removedWordFrequency); //Displaying all the elements from the linkedlist Console.WriteLine("****************"); Console.WriteLine("Displaying all the key value pairs in hash table"); hash.Display(); }
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(); }
static void Main(string[] args) { Console.WriteLine("Welcome to Hash Table Demo.."); MyMapNode <string, string> hash = new MyMapNode <string, string>(18); hash.Add("0", "Paranoids"); hash.Add("1", "are"); hash.Add("2", "not"); hash.Add("3", "paranoid"); hash.Add("4", "because"); 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"); string hash3 = hash.Get("3"); Console.WriteLine("3rd index value: " + hash3); string hash2 = hash.Get("2"); Console.WriteLine("2nd index value: " + hash2); string hash17 = hash.Get("17"); Console.WriteLine("17th index value: " + hash17); hash.Remove("17"); Console.WriteLine("17th index value removed.. "); Console.ReadKey(); }