Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            Node <int>       one     = new Node <int>(100);
            LinkedList <int> _linked = new LinkedList <int>();

            _linked.DeleteLastElement();
            _linked.AddFirst(100);
            _linked.DeleteLastElement();
            _linked.AddFirst(102);
            _linked.AddFirst(1033);
            _linked.AddLast(1000);
            _linked.AddLast(200);
            _linked.AddLast(2002);

            _linked.Print();
            Console.WriteLine();
            _linked.DeleteLastElement();


            _linked.Print();
            _linked.Delete(1000);
            Console.WriteLine();
            _linked.Print();
            bool _find = _linked.Find(200);

            Console.WriteLine(_find.ToString());

            Console.ReadLine();
        }
Exemplo n.º 2
0
        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();
        }
        static void Main(string[] args)
        {
            LinkedList myList = new LinkedList();

            try
            {
                int[] nums = { 42, 5, 9999, 777, 911 };
                foreach (int num in nums)
                {
                    myList.Insert(num);
                    Console.WriteLine($"{num} inserted to head of linked list.");
                }
                Console.WriteLine();

                Console.WriteLine($"Does 99 exist on the linked list?   {(myList.Includes(99) ? "Yes" : "No")}");
                Console.WriteLine($"Does 42 exist on the linked list?   {(myList.Includes(42) ? "Yes" : "No")}");
                Console.WriteLine($"Does 777 exist on the linked list?   {(myList.Includes(777) ? "Yes" : "No")}");
                Console.WriteLine();

                int[] moarNums = { 8, 16, -3 };
                foreach (int num in moarNums)
                {
                    myList.Insert(num);
                    Console.WriteLine($"{num} appended to linked list.");
                }
                Console.WriteLine();

                int[] manyNums       = { 25, 50, 75 };
                int[] manyNumsTarget = { 5, 911, 16 };
                for (int i = 0; i < manyNums.Length; i++)
                {
                    myList.InsertBefore(manyNumsTarget[i], manyNums[i]);
                    Console.WriteLine($"{manyNums[i]} added to list before {manyNumsTarget[i]}.");
                }
                Console.WriteLine();

                int[] suchNums       = { 15, 45, 60 };
                int[] suchNumsTarget = { 9999, -3, 75 };
                for (int i = 0; i < manyNums.Length; i++)
                {
                    myList.InsertAfter(suchNumsTarget[i], suchNums[i]);
                    Console.WriteLine($"{suchNums[i]} added to list after {suchNumsTarget[i]}.");
                }
                Console.WriteLine();

                myList.Print();
                Console.WriteLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                Console.WriteLine("End of test.");
            }
        }
Exemplo n.º 4
0
        static void TestMerge()
        {
            LinkedList list1 = new LinkedList(new Node(0));
            LinkedList list2 = new LinkedList(new Node(1));

            list1.AddLast(new Node(2));
            list2.AddLast(new Node(3));
            list1.AddLast(new Node(4));
            list2.AddLast(new Node(5));
            list1.Print();
            list2.Print();
            MergeLists(list1, list2).Print();
        }