예제 #1
0
 //case 3
 private static HTable Case3(HTable hTable, ref string[] array, ref string[] keyIndex)
 {
     if (hTable != null)
     {
         hTable.DeletePerson(ref array, ref keyIndex);
     }
     else
     {
         Console.WriteLine("Error! The hash-table is empty...");
     }
     Console.WriteLine(Index[5]);
     Console.ReadKey();
     return(hTable);
 }
예제 #2
0
        //Функция Main()
        private static void Main()
        {
            var pass   = 4;
            var hTable = new HTable(0);

            string[] array    = null;
            string[] keyIndex = null;
            while (true)
            {
                if (!PrintMenu(ref pass, ref hTable, ref array, ref keyIndex))
                {
                    break;
                }
            }
            Console.WriteLine(Index[5]);
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
0
        //case 2
        private static void Case2(HTable hTable)
        {
            if (hTable != null)
            {
                string searchedPerson;
                var    rgx = new Regex(@"[0-9]");
                Console.WriteLine("Write second name, name, father name of person, whose you want to find:");
                do
                {
                    searchedPerson = Console.ReadLine();
                    if (searchedPerson != null && searchedPerson.Replace(" ", "") == "")
                    {
                        Console.WriteLine("Write second name, name and father name of teh person:");
                    }
                    if (rgx.IsMatch(searchedPerson))
                    {
                        Console.WriteLine("Error! Written the number...");
                    }
                } while (searchedPerson == "" || rgx.IsMatch(searchedPerson));

                var searched = hTable.SearchPerson(searchedPerson);
                if (searched == null)
                {
                    Console.WriteLine("The given person wasn't in the hash-table...");
                }
                else
                {
                    Console.WriteLine(searched);
                }
            }
            else
            {
                Console.WriteLine("Error! The hash-table is empty...");
            }

            Console.WriteLine(Index[5]);
            Console.ReadKey();
        }
예제 #6
0
        //Печать меню для функции Main()
        private static bool PrintMenu(ref int pass, ref HTable hTable, ref string[] array, ref string[] keyIndex)
        {
            var ok = true;
            var sw = Print.Menu(pass, Index[0], Index[1], Index[2], Index[3], Index[6], Index[4]);

            switch (sw)
            {
            case 1:
                hTable = Case1(out pass, out array, out keyIndex);
                break;

            case 2:
                Case2(hTable);
                break;

            case 3:
                hTable = Case3(hTable, ref array, ref keyIndex);
                break;

            case 4:
                hTable = Case4(hTable, ref array, ref keyIndex);
                break;

            case 5:
                hTable.PrintHt();
                Console.WriteLine(Index[5]);
                Console.ReadKey();
                break;

            case 6:
                ok = false;
                break;
            }

            return(ok);
        }