Esempio n. 1
0
        static void Main(string[] args)
        {
            var charFinder    = new CharFinder();
            var nonRepeatChar = charFinder.FindFirstNonRepeatingCharacter("a apple product");
            var repeatChar    = charFinder.FindFirstRepeatedCharacter("a apple product");

            System.Console.WriteLine($"The first non repeat character is {nonRepeatChar}");
            System.Console.WriteLine($"The first repeated character is {repeatChar}");

            var hashTable = new HashTable(5);

            hashTable.Put(1, "A");
            hashTable.Put(2, "B");
            hashTable.Put(6, "C");
            System.Console.WriteLine($"Get value for key 6: {hashTable.Get(6)}");
            hashTable.Put(6, "D");
            System.Console.WriteLine($"Get value for key 6 after Update: {hashTable.Get(6)}");
            hashTable.Remove(6);
            System.Console.WriteLine($"Get value for key 6 after Remove: {hashTable.Get(6)}");
        }
        public static void CreateHashTable()
        {
            HashTable table = new HashTable();

            table.Add("brian", "love DSA");
            Console.WriteLine("Add: brian, love DSA");
            Console.WriteLine($"Found in Hash Table: {table.Contains("brian")}");

            table.Add("I am", "6'4");
            Console.WriteLine("Add: I am, 6'4");
            Console.WriteLine($"Found in Hash Table: {table.Contains("I am")}");

            table.Add("sonics", "2022 or bust");
            Console.WriteLine("Add: sonics, 2022 or bust");
            Console.WriteLine($"Found in Hash Table: {table.Contains("sonics")}");

            table.Add("we I turn this in", "i'll be above 90%!");
            Console.WriteLine("Add: we I turn this in, i'll be above 90%");
            Console.WriteLine($"Found in Hash Table: {table.Contains("we I turn this in")}");
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            HashTable hashTable = new HashTable();

            hashTable.Add("A", "Apple");
            Console.WriteLine("Adding key: A and value: Apple");
            Console.WriteLine($"In hash table: {hashTable.Contains("A")}");

            hashTable.Add("B", "Banana");
            Console.WriteLine("Adding key: B and value: Banana");
            Console.WriteLine($"In hash table: {hashTable.Contains("B")}");

            hashTable.Add("on", "fire");
            Console.WriteLine("Adding key: on and value: fire");
            Console.WriteLine($"In hash table: {hashTable.Contains("on")}");

            hashTable.Add("no", "space");
            Console.WriteLine("Adding key: no and value: space");
            Console.WriteLine($"In hash table: {hashTable.Contains("no")}");
        }
        public static void HashTableMadness()
        {
            HashTable ht    = new HashTable(1024);
            Node      node  = ht.Add("sushi", 2);
            Node      node2 = ht.Add("demi", 13);
            Node      node3 = ht.Add("coffee", 19);
            Node      node4 = ht.Add("kamehameha", 324);


            Console.WriteLine("confirming it contains added nodes");
            Console.WriteLine(ht.Contains("sushi"));
            Console.WriteLine(ht.Contains("demi"));
            Console.WriteLine(ht.Contains("coffee"));
            Console.WriteLine(ht.Contains("kamehameha"));


            Console.WriteLine("Finding nodes");
            Console.WriteLine(ht.Find("sushi"));
            Console.WriteLine(ht.Find("demi"));
            Console.WriteLine(ht.Find("coffee"));
            Console.WriteLine(ht.Find("kamehameha"));

            Console.WriteLine("Forcing collisions");
            ht.Add("Cat", 4);
            ht.Add("Doe", 9);
            ht.Add("fat", 17);
            ht.Add("gas", 20);

            Console.WriteLine($"Cat has an ascii value of {ht.asciiValue("Cat")}");
            Console.WriteLine($"Doe has an ascii value of {ht.asciiValue("Doe")}");
            Console.WriteLine($"fat has an ascii value of {ht.asciiValue("fat")}");
            Console.WriteLine($"gas has an ascii value of {ht.asciiValue("gas")}");



            Console.ReadKey();
        }
Esempio n. 5
0
 public HashSet()
 {
     this.hashTable = new HashTable <T, T>();
 }