static void Main(string[] args)
        {
            Node head = null;

            LinkedList.Append(ref head, 001);
            LinkedList.Append(ref head, 002);
            LinkedList.Append(ref head, 003);
            LinkedList.Append(ref head, 004);

            Console.WriteLine("Linked list:");
            LinkedList.Print(head);

            LinkedList.Reverse(ref head);

            Console.WriteLine();
            Console.WriteLine("Reversed Linked list:");
            LinkedList.Print(head);

            Console.WriteLine();
            //LinkedList.PrintRecursive(head);

            Console.WriteLine("Reverse of Reversed Linked list:");


            LinkedList.ReverseUsingRecursion(head);
            head = LinkedList.newHead;
            LinkedList.PrintRecursive(head);

            Console.ReadKey();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var myList = new LinkedList();

            myList.AddFirst(10);
            myList.AddLast(20);
            myList.AddLast(30);
            myList.AddFirst(5);

            System.Console.WriteLine($"Index of 10 is {myList.IndexOf(10)}");
            System.Console.WriteLine($"Whether MyList Contains 100? {myList.Contains(100)}");
            System.Console.WriteLine($"What is the size MyList? {myList.Size()}");

            // myList.RemoveFirst();
            // myList.RemoveLast();

            myList.Reverse();
            System.Console.WriteLine("Printing the List");
            var myListArray = myList.ToArray();

            Array.ForEach(myListArray, System.Console.WriteLine);

            System.Console.WriteLine($"2nd value from end: {myList.GetKthFromTheEnd(2)}");
        }