Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var list = new DoublyLinkedList <int>();

            for (int i = 0; i < 100; i++)
            {
                list.Add(new DoublyLinkedListNode <int>(i));
            }

            var node = list.GetNode(2);

            list.Remove(node);

            node = list.GetNode(1);

            list.AddAfter(node, new DoublyLinkedListNode <int>(100));

            var Count = list.Count();

            for (int i = 0; i < Count; i++)
            {
                var n = list.GetNode(i);
                Console.Write($"{n.Data} ");
            }

            Console.WriteLine();

            for (int i = Count; i >= 0; i--)
            {
                var n = list.GetNode(i);
                Console.Write($"{n.Data} ");
            }

            Console.ReadKey();
        }
Exemplo n.º 2
0
        public static void Main()
        {
            DoublyLinkedList <int> doublyLinkedList = new DoublyLinkedList <int>();

            doublyLinkedList.Add(1);
            doublyLinkedList.Add(2);
            doublyLinkedList.Add(3);
            doublyLinkedList.Add(4);
            doublyLinkedList.Add(5);
            doublyLinkedList.InsertAfter(5, 99);

            doublyLinkedList.Delete(5);

            Console.WriteLine(doublyLinkedList.Contains(5));

            foreach (object item in doublyLinkedList)
            {
                Console.WriteLine(item);
            }

            foreach (object item in doublyLinkedList.Reverse())
            {
                Console.WriteLine(item);
            }

            CircularDoublyLinkedList <int> circularDoublyLinkedList = new CircularDoublyLinkedList <int>();

            circularDoublyLinkedList.Add(1);
            circularDoublyLinkedList.Add(2);
            circularDoublyLinkedList.Add(3);
            circularDoublyLinkedList.Add(4);
            circularDoublyLinkedList.Add(5);

            circularDoublyLinkedList.Delete(3);

            circularDoublyLinkedList.InsertAfter(2, 99);

            Console.WriteLine(circularDoublyLinkedList.Contains(3));

            foreach (object item in circularDoublyLinkedList)
            {
                Console.WriteLine(item);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            DoublyLinkedList <string> list = new DoublyLinkedList <string>();

            list.Add("Два");
            list.Add("Три");
            list.Add("Четыре");
            list.Add("Пять");
            list.AppendFirst("Раз");

            foreach (var s in list.GetEnumerator())
            {
                Console.Write(s + " ");
            }

            Console.WriteLine();

            foreach (var s in list.GetEnumerator(true))
            {
                Console.Write(s + " ");
            }

            Console.WriteLine();
            Console.WriteLine(list.Count);

            if (list.Contains("Три"))
            {
                list.Remove("Три");
            }

            if (!list.IsNull)
            {
                Console.WriteLine(list.Count);
            }

            foreach (var s in list.GetEnumerator())
            {
                Console.Write(s + " ");
            }

            Console.ReadKey();
        }
Exemplo n.º 4
0
        private static void Main()
        {
            var doublyLinkedList = new DoublyLinkedList();

            doublyLinkedList.Add(5);
            doublyLinkedList.Add(10);
            doublyLinkedList.Add(15);
            Console.WriteLine(doublyLinkedList.Contains(10));
            Console.WriteLine(doublyLinkedList.Contains(25));
            Console.WriteLine(doublyLinkedList.Remove(10));
            Console.WriteLine(doublyLinkedList.FindByIndex(1));
            Console.WriteLine(doublyLinkedList.Count);
            Console.WriteLine(doublyLinkedList[1]);
            doublyLinkedList[1] = 20;
            Console.WriteLine(doublyLinkedList[1]);
            doublyLinkedList.Clear();
            doublyLinkedList.Add(1);
            doublyLinkedList.Add(3);
            Console.WriteLine("Insert after: " + doublyLinkedList.InsertBefore(1, 2));
            Console.Read();
        }
        static void Main(string[] args)
        {
            // DoublyLinkedList instanziieren
            var list = new DoublyLinkedList <string>();

            list.Add("Erster Wert");
            list.Add("Zweiter Wert");
            list.Add("Dritter Wert");
            list.Add("Vierter Wert");

            list.Remove("Dritter Wert");

            foreach (string name in list)
            {
                Console.WriteLine(name);
            }

            Console.WriteLine(list);

            Console.WriteLine("Weiter mit ENTER . . .");
            Console.ReadLine();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            DoublyLinkedList <string> linkedList = new DoublyLinkedList <string>();

            // добавление элементов
            linkedList.Add("Bob");
            linkedList.Add("Bill");
            linkedList.Add("Tom");
            linkedList.AddFirst("Kate");
            foreach (var item in linkedList)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("-----------------------");

            // удаление
            linkedList.Remove("Bill");

            // перебор с последнего элемента
            foreach (var t in linkedList.BackEnumerator())
            {
                Console.WriteLine(t);
            }
        }
Exemplo n.º 7
0
 static void Main(string[] args)
 {
     DoublyLinkedList test = new DoublyLinkedList();
     test.InsertAt(0, 1);
     test.InsertAt(1, 2);
     test.Add(3);
     Console.WriteLine("List elements:");
     test.Print();
     test.RemoveAt(0);
     Console.WriteLine("List elements after removing element at index 0:");
     test.Print();
     test.InsertAt(2, 4);
     Console.WriteLine("List elements after inserting an element at index 2(after the last element):");
     test.Print();
     Console.WriteLine("List elements after changing element data at index 1 with '5':");
     test.ChangeDataAtIndex(1, 5);
     test.Print();
     Console.WriteLine("List elements after changing element with value '2' to '3':");
     test.ChangeElementData(2, 3);
     test.Print();
     Console.WriteLine("List elements after removing element with value '4'");
     test.Remove(4);
     test.Print();
     object element = test.GetElementData(1);
     Console.WriteLine("Value of element at index 1:" + element);
     Console.WriteLine("Index of element with value 3:{0}", test.IndexOf(3));
     Console.WriteLine("List contains element with value = '5': {0}", (test.Contains(5)) ? "Yes" : "No");
     Console.WriteLine("Is list empty? - {0}", (test.IsEmpty) ? "Yes" : "No");
 }