Esempio n. 1
0
        static void Main(string[] args)
        {
            MyHashTable ht = new MyHashTable(100);

            ht.addItem("test");
            ht.addItem("hhhhh");
            ht.printItems();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            MyHashTable <object> hash = new MyHashTable <object>(1);

            hash.Add("poop", "poopy");
            var poop = hash.Table[0].ToList();

            foreach (var i in poop)
            {
                Console.WriteLine(i.Value);
            }
            Console.WriteLine(hash.Table.First());
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            // Performance test
            int    operations = 1000000;
            int    elements   = 50000;
            Random random     = new Random();

            MyHashTable <string, int> hashTable = new MyHashTable <string, int>();

            for (int i = 0; i < elements; i++)
            {
                hashTable.Add(random.Next().ToString() + "asd", i);
            }

            var hashSet = new HashSet <string>();

            for (int i = 0; i < elements; i++)
            {
                hashSet.Add(random.Next().ToString() + "asd");
            }

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            for (int i = 0; i < operations; i++)
            {
                hashTable.ContainsKey("asd");
            }

            stopwatch.Stop();
            Console.WriteLine("MyHashTable: " + stopwatch.Elapsed);

            stopwatch.Reset();
            stopwatch.Start();
            for (int i = 0; i < operations; i++)
            {
                hashSet.Contains("asd");
            }

            stopwatch.Stop();
            Console.WriteLine("HashSet: " + stopwatch.Elapsed);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {

            MyHashTable tbl = new MyHashTable(10, x=>(((x % 1000) * (x % 1000)) 
                                                        %1000)*2153%1000);

            tbl.Insert(new Elem() { Key = 52, Value = "rrrrrrrrrrr" });
            tbl.Insert(new Elem() { Key = 73, Value = "gggggg" });
            tbl.Insert(new Elem() { Key = 16, Value = "kkkkkkkkkk" });
            tbl.Insert(new Elem() { Key = 461, Value = "aaaaaaaa" });
            tbl.Insert(new Elem() { Key = 33349, Value = "bbbbbbbbbbb" });

            tbl.Show();

            var el = tbl.GetElem(73);
            Console.WriteLine($"{el.Key} {el.Value}");




        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            FirstNonRepeatingChar obj = new FirstNonRepeatingChar();
            string ch = obj.FindFirstNonRepeatingChar("a green apple");

            Console.WriteLine(obj.ToString());
            Console.WriteLine("First Non-Repeating character is " + ch);


            FirstRepeatedCharacter rep = new FirstRepeatedCharacter();
            char repCh = rep.FindFirstRepeatedCharacter("a green apple");

            Console.WriteLine("First Repeated character is " + repCh);


            MyHashTable hashtbl = new MyHashTable();

            //hashtbl.remove(6);

            hashtbl.put(6, "A");
            hashtbl.put(8, "B");
            hashtbl.put(11, "C");
            hashtbl.put(6, "D");
            Console.WriteLine("Value of key 11 is " + hashtbl.get(11));
            Console.WriteLine("Value of key 10 is " + hashtbl.get(10));

            //hashtbl.remove(6);
            //hashtbl.remove(7);

            //================ Most frequently repeated item in array ==============//
            HashTableExercise ex = new HashTableExercise();
            var mostRepeated     = ex.GetMostFrequent(new int[12] {
                1, 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 4
            });

            Console.WriteLine("Most Repeated element in array is :" + mostRepeated);

            var uniquePairs = ex.countPairsWithDiff(new int[7] {
                1, 7, 5, 9, 2, 12, 3
            }, 2);

            Console.WriteLine("Count of numbers of unique pairs with difference of 2 :" + uniquePairs);

            var indices = ex.twoSum(new int[4] {
                2, 7, 11, 15
            }, 9);

            //================== Linear Probing Hash Table ========================//

            LinearProbingHashTable linearProbing = new LinearProbingHashTable();

            linearProbing.put(1, 2);
            linearProbing.put(11, 3);
            linearProbing.put(17, 5);
            linearProbing.put(3, 4);
            linearProbing.put(2, 10);
            //linearProbing.put(22, 11);

            linearProbing.remove(17);

            Console.WriteLine("Size of array is :" + linearProbing.size());

            Console.WriteLine("Value of key 11 is :" + linearProbing.getValue(11));

            Console.ReadLine();
        }