Пример #1
0
        public DuplexLinkedList <T> Reverse()
        {
            var result = new DuplexLinkedList <T>();

            var current = Tail;

            while (current != null)
            {
                result.Add(current.Data);
                current = current.Previous;
            }

            return(result);
        }
Пример #2
0
        static void menu2()
        {
            var duplexList = new Model.DuplexLinkedList <int>();
            int menu;

            while (true)
            {
                Start();


                menu = Convert.ToInt32(Console.ReadLine());
                int data;
                int id;
                switch (menu)
                {
                case 1:
                    duplexList.Print();
                    break;

                case 2:
                    Console.Write("Введите значение: ");
                    data = Convert.ToInt32(Console.ReadLine());
                    duplexList.Add(data);

                    break;

                case 3:
                    Console.Write("Введите значение: ");
                    id = Convert.ToInt32(Console.ReadLine());
                    duplexList.DeleteByID(id);
                    break;

                case 4:
                    Console.WriteLine($"В списке: {duplexList.Count} элементов");
                    break;

                case 5:
                    Console.Write("Введите значение: ");
                    id = Convert.ToInt32(Console.ReadLine());
                    duplexList.SwapById(id);
                    break;

                case 6:
                    var temp = new Model.DuplexLinkedList <int>();
                    Console.Write("Введите значения: ");
                    string   str      = Console.ReadLine();
                    string[] elements = str.Split(' ');
                    foreach (var el in elements)
                    {
                        temp.Add(Convert.ToInt32(el));
                    }
                    foreach (var e in temp)
                    {
                        duplexList.Add(Convert.ToInt32(e));
                    }
                    break;

                case 7:
                    duplexList.Clear();
                    break;

                case 8:
                    string   text             = System.IO.File.ReadAllText(@"C:\Users\Mi Store\source\repos\algorithms\lab1\lab1\int.txt");
                    string[] elementsFromFile = text.Split(' ');
                    foreach (var el in elementsFromFile)
                    {
                        if (el != "")
                        {
                            duplexList.Add(Convert.ToInt32(el));
                        }
                    }

                    break;

                case 9:
                    string elToFile = "";
                    foreach (var el in duplexList)
                    {
                        elToFile += $"{Convert.ToString(el)} ";
                    }
                    //Console.WriteLine(elToFile);
                    System.IO.File.WriteAllText(@"C:\Users\Mi Store\source\repos\algorithms\lab1\lab1\int.txt", elToFile);
                    break;

                case 0:
                    return;

                default:
                    Console.WriteLine("error");
                    break;
                }
                Console.WriteLine("--------------------------------------------");
            }
        }