Exemple #1
0
        /// <summary>
        /// Поиск в хэш-таблице
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool Find(long key)
        {
            table = Program.table;

            long hash = key % size;

            if (!isEmpty)
            {
                while (table[hash] != null && table[hash].GetKey() % size != key % size)
                {
                    hash = (hash + 1) % size;
                }
                Guest current = table[hash];
                if (current != null)
                {
                    while (current.GetKey() != key && current.GetNextNode() != null)
                    {
                        current = current.GetNextNode();
                    }
                    if (current.GetKey() == key)
                    {
                        return(true);
                    }

                    /*else
                     * {
                     *  return false;
                     * }*/
                }
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Поиск в хэш-таблице
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public Guest FindGuest(long key)
        {
            table = Program.table;

            long hash = key % size;

            while (table[hash] != null && table[hash].GetKey() % size != key % size)
            {
                hash = (hash + 1) % size;
            }
            Guest current = table[hash];

            if (current == null)
            {
                return(null);
            }
            else
            {
                while (current.GetKey() != key && current.GetNextNode() != null)
                {
                    current = current.GetNextNode();
                }
                if (current.GetKey() == key)
                {
                    return(current);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Удаление элемента
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool Remove(long key)
        {
            table = Program.table;

            long hash = key % size;

            if (isEmpty)
            {
                return(false);
            }
            else
            {
                while (table[hash] != null && table[hash].GetKey() % size != key % size)
                {
                    hash = (hash + 1) % size;
                }
                Guest current  = table[hash];
                Guest previous = null;

                if (current != null)
                {
                    while (current.GetKey() != key && current.GetNextNode() != null)
                    {
                        previous = current;
                        current  = current.GetNextNode();
                    }
                    if (current.GetKey() == key)
                    {
                        if (previous != null)
                        {
                            previous.next = current.next;
                            if (current.next == null)
                            {
                                previous.next = null;
                            }
                        }
                        else
                        {
                            table[hash] = null;
                        }
                        count--;
                        if (count == 0)
                        {
                            isEmpty = true;
                        }
                        return(true);
                    }
                }
                return(false);
            }
        }
Exemple #4
0
        // алгоритм поиска БМ
        private void SearchString(Guest current, int m, int[] badChar, string pat, int count)
        {
            if (current != null)
            {
                int n = current.FIO.Length;

                bool flag = false;
                int  s    = 0;
                while (s <= (n - m))
                {
                    int j = m - 1;

                    while (j >= 0 && pat[j] == current.FIO[s + j])
                    {
                        --j;
                    }

                    if (j < 0)
                    {
                        flag = true;
                        s   += (s + m < n) ? m - badChar[current.FIO[s + m]] : 1;
                    }
                    else
                    {
                        s += Math.Max(1, j - badChar[current.FIO[s + j]]);
                    }
                }
                if (flag)
                {
                    Program.guests.Add(current);
                }
                if (current.GetNextNode() != null)
                {
                    current = current.GetNextNode();
                    SearchString(current, m, badChar, pat, count);
                }
            }
            else
            {
                while (count < size - 1)
                {
                    count++;
                    current = table[count];
                    if (current != null)
                    {
                        SearchString(current, m, badChar, pat, count);
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Вывод всех элементов в консоль
        /// </summary>
        public void Print()
        {
            Guest current = null;

            Console.WriteLine("Зарегистрированные постояльцы: ");
            for (int i = 0; i < size; i++)
            {
                current = table[i];
                while (current != null)
                {
                    Console.WriteLine("\nПаспорт: {0}", current.passport_number);
                    Console.WriteLine("ФИО: {0}", current.FIO);
                    Console.WriteLine("Год рождения: {0}", current.birth_year);
                    Console.WriteLine("Адрес: {0}", current.adress);
                    Console.WriteLine("Цель прибытия: {0}", current.purpose_of_visit);
                    current = current.GetNextNode();
                }
            }
        }