Esempio n. 1
0
        public void AddElementTest()
        {
            hashTable.AddElement(15);
            hashTable.AddElement(115);

            Assert.IsTrue(hashTable.IsContainingElement(15));
            Assert.IsTrue(hashTable.IsContainingElement(115));
        }
Esempio n. 2
0
        public void DeleteElementTest()
        {
            hashTable1.AddElement(16);
            hashTable1.AddElement(73);
            AddElements(hashTable1);

            hashTable1.DeleteElement(73);
            hashTable1.DeleteElement(16);

            AssertsFalse(hashTable1);

            hashTable2.AddElement(16);
            hashTable2.AddElement(73);
            AddElements(hashTable2);

            hashTable2.DeleteElement(73);
            hashTable2.DeleteElement(16);

            AssertsFalse(hashTable2);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            StreamReader sr = new StreamReader("Schülerliste 3-5 Klasse V2.csv");

            List <Person> pList = new List <Person>();

            int idx = 0;

            while (!sr.EndOfStream)
            {
                string s = sr.ReadLine();
                if (idx != 0)
                {
                    string[] split = s.Split(';');

                    Person p = new Person(split[0], split[1], split[2]);

                    pList.Add(p);
                }

                idx++;
            }

            HashTable ht = new HashTable((int)(idx * 1.3));

            pList.ForEach(x =>
            {
                ht.AddElement(x);
            });

            var list  = ht.GetTable();
            int count = 0;

            list.ToList().ForEach(x =>
            {
                if (x != null)
                {
                    Console.WriteLine(count + ": " + x.ToString());
                    count++;
                }
            });

            Console.WriteLine("Collision Count: " + ht.CollisionCount);

            Console.ReadKey();
        }
Esempio n. 4
0
 /// <summary>
 /// добавить в хэш-таблицу значения 15, 72, 115
 /// </summary>
 private void AddElements(HashTable hashTable)
 {
     hashTable.AddElement(15);
     hashTable.AddElement(72);
     hashTable.AddElement(115);
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            int       select    = 0;
            HashTable hashTable = new HashTable();
            bool      isNext    = true;

            Console.WriteLine("lol".CompareTo("lol"));
            while (isNext)
            {
                Console.WriteLine("Please, select and print number:");
                Console.WriteLine("1) Read data from file");
                Console.WriteLine("2) Input element from keyboard");
                Console.WriteLine("3) Find elemnt");
                Console.WriteLine("4) Get middle time");
                Console.WriteLine("5) Exit");
                select = select.InputFromKeyBoard();
                switch (select)
                {
                case 1:
                {
                    Console.WriteLine("Input file name");
                    bool statusRead = hashTable.AddElementsFromFile(Console.ReadLine());
                    if (statusRead)
                    {
                        Console.WriteLine("Data was sucсessfully loaded");
                        Console.WriteLine("Middle count compares: "
                                          + Math.Round(hashTable.GetMiddleCountCompares(), 3).ToString());
                        Console.WriteLine("Middle count conflicts: "
                                          + Math.Round(hashTable.GetMiddleCountConflicts(), 3).ToString());
                    }
                    else
                    {
                        Console.WriteLine("This file does not exist");
                        Console.WriteLine("Repeat, please");
                    }
                    break;
                }

                case 2:
                {
                    Console.WriteLine("Input value");
                    bool statusAdd = hashTable.AddElement(Console.ReadLine());
                    if (statusAdd)
                    {
                        Console.WriteLine("this element was successfully added");
                        Console.WriteLine("Count compares: "
                                          + hashTable.GetLastCountCompare().ToString());
                        Console.WriteLine("Count conflicts: "
                                          + hashTable.GetLastCountConflict().ToString());
                    }
                    else
                    {
                        Console.WriteLine("this element already exist");
                        Console.WriteLine("Repeat, please");
                    }
                    break;
                }

                case 3:
                {
                    Console.WriteLine("Input value");
                    bool statusFind = hashTable.FindElement(Console.ReadLine());
                    if (statusFind)
                    {
                        Console.WriteLine("This element was successefully found");
                        Console.WriteLine("Count compares: "
                                          + hashTable.GetLastCountCompare().ToString());
                        Console.WriteLine("Count conflicts: "
                                          + hashTable.GetLastCountConflict().ToString());
                    }
                    else
                    {
                        Console.WriteLine("This element does not exists");
                        Console.WriteLine("Repeat, please");
                    }
                    break;
                }

                case 4:
                {
                    Console.WriteLine("Middle count compares: "
                                      + Math.Round(hashTable.GetMiddleCountCompares(), 3).ToString());
                    Console.WriteLine("Middle count conflicts: "
                                      + Math.Round(hashTable.GetMiddleCountConflicts(), 3).ToString());
                    break;
                }

                case 5:
                {
                    isNext = false;
                    break;
                }

                default:
                {
                    Console.WriteLine("Repeat, please");
                    break;
                }
                }
            }
        }