Пример #1
0
        //case 4
        private static HTable Case4(HTable hTable, ref string[] array, ref string[] keyIndex)
        {
            Array.Resize(ref array, array.Length + 1);
            Array.Resize(ref keyIndex, keyIndex.Length + 1);
            var    rgx = new Regex(@"[0-9]");
            string addPerson;

            string[] add;
            Console.WriteLine("Write second name, name and father name of the person, whose you want to add:");
            do
            {
                addPerson = Console.ReadLine();
                if (rgx.IsMatch(addPerson))
                {
                    Console.WriteLine("Error! Written the number...");
                }
                var separator = " ".ToCharArray();
                add = addPerson.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                if (add.Length != 3)
                {
                    Console.WriteLine(
                        "Error! The wrong input...\nWrite second name, name and father name of teh person:");
                }
            } while (addPerson == "" || rgx.IsMatch(addPerson) || add.Length != 3);

            var rnd    = new Random();
            var person = new Person(add[0], add[1], add[2], CreateAccount(rnd), rnd.Next(0, 1000000).ToString());

            array[array.Length - 1]       = person.ToString();
            keyIndex[keyIndex.Length - 1] = string.Concat(add[0], add[1], add[2]);
            if (hTable.SearchPerson(addPerson) == null)
            {
                hTable.FillingHashTable(keyIndex, array, hTable.Size + 1, out _);
                Console.WriteLine("{0} is added to the hash-table:", add[0] + " " + add[1] + " " + add[2]);
                hTable.PrintHt();
            }
            else
            {
                Console.WriteLine("The person is already added to the hash-table...");
            }

            Console.WriteLine(Index[5]);
            Console.ReadKey();
            return(hTable);
        }
Пример #2
0
        //Создание хэш-таблицы
        private static HTable CreateHashTable(string[] array, string[] key, out int k, out int count)
        {
            HTable ht;

            k     = 0;
            count = 0;
            Console.WriteLine("Write the size of hash-table");
            var size = ReadLib.ReadLib.ReadVGran(0);

            if (size == 0)
            {
                Console.WriteLine("Error! The hash-table is empty...");
                return(null);
            }

            ht = new HTable(size);
            ht.FillingHashTable(key, array, size, out count);
            return(ht);
        }