コード例 #1
0
        /// <summary>
        /// Демонстрация работы базового DuplexLinkedList.
        /// </summary>
        public void DuplexLinkedList()
        {
            var duplexList = new DuplexLinkedList <int>();

            Console.WriteLine($"DuplexLinkedList - count: {duplexList.Count}");
            var rndValue = rnd.Next(0, 100);

            duplexList.Add(rnd.Next(0, 100));
            duplexList.Add(rndValue);
            duplexList.Add(rnd.Next(0, 100));
            duplexList.Add(rnd.Next(0, 100));
            duplexList.Add(rnd.Next(0, 100));

            Console.WriteLine($"DuplexLinkedList - count: {duplexList.Count}");

            duplexList.Delete(rndValue);

            Console.WriteLine($"DuplexLinkedList - count after delete: {duplexList.Count}");

            foreach (var item in duplexList)
            {
                Console.WriteLine($"DuplexLinkedList - Item: {item}");
            }

            var reverse = duplexList.Reverse();

            Console.WriteLine("\nAfter Reverse..\n");
            foreach (var item in reverse)
            {
                Console.WriteLine($"DuplexLinkedList - Item: {item}");
            }
        }
コード例 #2
0
        /// <summary>
        /// Реверс элементов.
        /// </summary>
        /// <returns>Результат реверса.</returns>
        public DuplexLinkedList <T> Reverse()
        {
            var result = new DuplexLinkedList <T>();

            var current = Tail;

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

            return(result);
        }