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

            dll.Print();

            //Push 1 at the beginning of the list
            dll.Push(1);

            //Push 2 at the beginning of the list
            dll.Push(2);

            //Push 4 after Head.Next
            var four = dll.InsertAfter(dll.Head.Next, 4);

            //Push 5 before 1
            dll.InsertBefore(dll.Head.Next, 5);

            //Append 9
            var nine = dll.Append(9);

            //Deletes 2 and makes 1 Head
            dll.Delete(dll.Head);

            //Delete 9
            dll.Delete(nine);

            //Delete 4
            dll.Delete(four);

            Console.ReadLine();

            dll.Print();
            //Finish program
            Console.ReadLine();
        }
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);
            }
        }