Esempio n. 1
0
        public static void displayHashes()
        {
            Hashtables hashTables = new Hashtables();

            hashTables.Add("abc", "Josie");
            hashTables.Add("Dog", "Woof");
            hashTables.Add("333", "ponies");
            hashTables.Add("moons", "44");
            hashTables.Add("cba", "Doctor"); //Collision abc same as cba
            Console.WriteLine($"Should return as 'True' for contains:  {hashTables.Contains("moons")}");
            Console.WriteLine($"Should return as 'False' for contains: {hashTables.Contains("planet")}");
            Console.WriteLine($"Should return the value 'Woof' from key:  {hashTables.GetValue("Dog")}");
            Console.WriteLine($"Should return the value 'Doctor' from collision: {hashTables.GetValue("cba")}");
        }
        public static List <int> TreeIntersection(BinaryTree one, BinaryTree two)
        {
            //Final output as List instead of int array.
            List <int> output = new List <int>();

            Hashtables hashTables = new Hashtables();

            //Pass Binary trees into List<>
            List <int> treeOneList = one.PreOrder(one.Root);
            List <int> treeTwoList = two.PreOrder(two.Root);

            //Add all of tree one into hashtable
            foreach (var item in treeOneList)
            {
                hashTables.Add(item.ToString(), item);
            }

            //compare tree two if buckets in hashtable are already occupied.
            //If collision occurs add that number to the List output.
            foreach (var item in treeTwoList)
            {
                if (hashTables.Contains(item.ToString()))
                {
                    output.Add(item);
                }
            }

            /*
             * foreach (var item in output)
             * {
             *  Console.WriteLine(item);
             * }*/

            return(output);
        }
Esempio n. 3
0
        public void GetTrue(string key, object value)
        {
            Hashtables hashTables = new Hashtables();

            hashTables.Add(key, value);

            Assert.True(hashTables.Contains(key));
        }
Esempio n. 4
0
        public void GetFalse3()
        {
            Hashtables hashTables = new Hashtables();

            hashTables.Add("abc", "Josie");
            hashTables.Add("Dog", "Woof");
            hashTables.Add("333", "ponies");
            hashTables.Add("moons", "44");

            Assert.False(hashTables.Contains("three"));
        }
Esempio n. 5
0
        public static string RepeatedWord(string input)
        {
            string[]   listOfWord = input.ToLower().Split(',', ' ', '.');
            Hashtables hashWords  = new Hashtables();

            for (int i = 0; i < listOfWord.Length; i++)
            {
                string temp = listOfWord[i];

                if (hashWords.Contains(temp))
                {
                    return(temp);
                }
                else
                {
                    hashWords.Add(temp, temp);
                }
            }
            return("No repeated word found.");
        }