Exemple #1
0
        static void TestHashTable()
        {
            HashTable.HashTable <string, string> hash = new HashTable.HashTable <string, string>(17);

            hash.Add("1", "item 1");
            hash.Add("2", "item 2");
            hash.Add("hola", "amigo");

            string one = hash.Find("1");

            Console.WriteLine("should be item 1: {0}", one);
            string two = hash.Find("2");

            Console.WriteLine("should be item 2: {0}", two);
            string amigo = hash.Find("hola");

            Console.WriteLine("should be amigo: {0}", amigo);
            hash.Remove("1");
            var k = hash.Find("1");
        }
Exemple #2
0
        public static void PrintActions()
        {
            var hashTable = new HashTable();
            var random    = new Random();

            // Add in array
            Console.WriteLine("\r\n-------------------------");
            Console.WriteLine($"Insere na lista com Hash Table");
            Console.WriteLine("-------------------------\r\n");
            hashTable.AddByArray("Mauricio", random.Next(100));
            hashTable.AddByArray("Guilherme", random.Next(100));
            hashTable.AddByArray("Jose", random.Next(100));
            Console.WriteLine($"{hashTable}");

            // Add
            var hashTableNew = new HashTable();

            Console.WriteLine("\r\n-------------------------");
            Console.WriteLine($"Insere na lista com Hash Table");
            Console.WriteLine("-------------------------\r\n");
            hashTableNew.Add("Ricardo", random.Next(100));
            hashTableNew.Add("Cabral", random.Next(100));
            hashTableNew.Add("Rafa", random.Next(100));
            Console.WriteLine($"{hashTableNew}");

            // Exception
            var hashTableExcetion = new HashTable();

            Console.WriteLine("\r\n-------------------------");
            Console.WriteLine($"Gera Exception Hash Table");
            Console.WriteLine("-------------------------\r\n");
            hashTableExcetion.Add("Ricardo", random.Next(100));
            hashTableExcetion.Add("Rafa", random.Next(100));
            //hashTableExcetion.Add("Ricardo", random.Next(100));
            Console.WriteLine($"{hashTableExcetion}");
        }