Exemplo n.º 1
0
        private static void TestHashTable()
        {
            Grades grade1 = new Grades(72, "well", 63);
            Grades grade2 = new Grades(94, "not bad", 87);
            Grades grade3 = new Grades(72, "well", 63);
            Grades grade4 = new Grades(94, "not bad", 87);

            Student student1 = new Student("Vladislav", "Vladislavov", 1);
            Student student2 = new Student("Ivan", "Ivanov", 2);
            Student student3 = new Student("Petr", "Petrov", 3);
            Student student4 = new Student("Sydor", "Sydorov", 4);
            Student student5 = new Student("Maxim", "Sydorov", 7);



            MyHashTable <Student, Grades> studentToGrades = new MyHashTable <Student, Grades>();

            studentToGrades.Add(student1, grade1);
            studentToGrades.Add(student2, grade2);
            studentToGrades.Add(student3, grade3);
            studentToGrades.Add(student4, grade4);
            studentToGrades.Add(student4, grade4);
            studentToGrades.Add(student5, grade1);

            Console.WriteLine("Ivan Ivanov: " + studentToGrades.Get(student2));
            Console.WriteLine("Vladislav Vladislavov: " + studentToGrades.Get(student1));
            Console.WriteLine("Petr Petrov: " + studentToGrades.Get(student3));
            Console.WriteLine("Sydor Sydorov: " + studentToGrades.Get(student4));

            Console.WriteLine("Hash Table:");
            Console.WriteLine(studentToGrades.ToString());

            studentToGrades.Remove(student3);
            Console.WriteLine();
            Console.WriteLine("Petr Petrov: " + studentToGrades.Get(student3));
            Console.WriteLine("Maxim: " + studentToGrades.Get(student5));

            Console.WriteLine();
            Console.WriteLine(studentToGrades.ToString());
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            MyHashTable table  = new MyHashTable(100);
            Random      random = new Random();

            Console.WriteLine("60 random numbers: ");
            for (int i = 0; i < 60; i++)
            {
                int number = random.Next(1, 450);
                Console.Write(number + " ");
                table.Add(number);
            }
            Console.WriteLine();

            Console.WriteLine("Collisions: " + table.CountCollisions());

            Console.WriteLine("Table: ");
            table.PrintTable();

            Console.WriteLine();

            Console.WriteLine("90 random numbers: ");
            for (int i = 0; i < 90; i++)
            {
                int number = random.Next(1, 450);
                Console.Write(number + " ");
                table.Add(number);
            }
            Console.WriteLine();


            Console.WriteLine("Collisions: " + table.CountCollisions());

            Console.WriteLine("Table: ");
            table.PrintTable();
        }