Пример #1
0
 public TwoWayLinkedList(int n, int StartNum = 1)
 {
     Data = StartNum;
     if (n <= 1)
     {
         return;
     }
     next          = new TwoWayLinkedList(n - 1, StartNum + 1);
     next.previous = this;
 }
Пример #2
0
        static void Main(string[] args)
        {
            int num = 0;

            WriteLine("Введите длину сипска");
            while (!int.TryParse(ReadLine(), out num) || num <= 0)
            {
                WriteLine("Ошибка, введите натуральное число");
            }


            var options = new[] { new[] { "Удалить" }, new[] { "Найти" }, new[] { "Выход" } };
            var list    = new TwoWayLinkedList(num);

            do
            {
                Clear();
                for (int i = 0; i < list.Length; i++)
                {
                    Write(" {0}", list[i]);
                }
                WriteLine();

                var pos = SelectorXY(options);
                switch (pos.Item2)
                {
                case 0:
                    WriteLine("Какой элемент удалить?");
                    while (!int.TryParse(ReadLine(), out num) || num < 0 || num >= list.Length)
                    {
                        WriteLine("Ошибка, введите положительное число меньше длины списка");
                    }
                    list.Delete(num - 1);

                    WriteLine("\nРезультат");
                    for (int i = 0; i < list.Length; i++)
                    {
                        Write(" {0}", list[i]);
                    }
                    WriteLine();

                    ReadKey(true);
                    break;

                case 1:
                    WriteLine("Что найти?");
                    while (!int.TryParse(ReadLine(), out num))
                    {
                        WriteLine("Введите число");
                    }
                    var s = list.Search(num);

                    if (s != -1)
                    {
                        WriteLine("Индекс найденного элемента: {0}", s + 1);
                    }
                    else
                    {
                        WriteLine("Элемент не найден");
                    }
                    ReadKey(true);
                    break;

                case 2:
                    return;
                }
            }while (true);
        }