/// <summary> /// This method wil take in 2 lists that will store the preordered binary trees. /// Next the values at each tree are hashed into the hash table. /// The first for loop will add the first list into the hash table /// The second list we will create a index for the hash table /// We will do a check using the contains method to see if both values that were hashed are contained in the table /// If they are contained we add to the new final list, otherwise add to table /// </summary> /// <param name="storedTreeValues"></param> /// <param name="storedTreeValues2"></param> /// <param name="tree1"></param> /// <param name="tree2"></param> /// <returns></returns> public static List <int> TreeIntersection(List <int> storedTreeValues, List <int> storedTreeValues2, BinaryTree tree1, BinaryTree tree2) { // Setting up tree 1 iteration to final list HashTableSetup table = new HashTableSetup(1024); tree1.PreOrder(tree1.Top, storedTreeValues); tree2.PreOrder(tree2.Top, storedTreeValues2); List <int> finalList = new List <int>(); int index; for (int i = 0; i < storedTreeValues.Count; i++) { table.Add(storedTreeValues[i].ToString(), storedTreeValues[i].ToString()); for (int j = 0; j < storedTreeValues2.Count; j++) { index = table.Hash(storedTreeValues2[j].ToString()); if (table.Contains(storedTreeValues2[j].ToString(), index) && table.Contains(storedTreeValues[i].ToString(), index)) { finalList.Add(storedTreeValues2[j]); } else { table.Add(storedTreeValues2[j].ToString(), index); } } } return(finalList); }
/// <summary> /// This function will first split our word by all delimeters specified. /// We will then create a hash table and hash each word that is split. /// If the word is contained withing the linked list it will return that value, if not /// we will add it to the linked list /// </summary> /// <param name="repeatedWord"></param> /// <returns></returns> public static string RepeatedWords(string repeatedWord) { string[] splitInput = repeatedWord.Split(' ', ',', ':', ';', '.'); HashTableSetup table = new HashTableSetup(1024); int index; for (int i = 0; i < splitInput.Length; i++) { index = table.Hash(splitInput[i].ToLower()); if (table.Contains(splitInput[i].ToLower(), index)) { return(splitInput[i].ToLower()); } else { table.Add(splitInput[i].ToLower(), index); } } return(null); }
public void AddingKeyAndValueToHashTable(Object key, int indx) { HashTableSetup table = new HashTableSetup(1024); Assert.Equal(indx, table.Hash(key)); }