Beispiel #1
0
        static void TestLL()
        {
            LinkList list = new LinkList(new Node(5));

            list.Add(new Node(10));
            list.Add(new Node(25));
            list.Add(new Node(50));
            list.Print();

            Node found = list.Find(10);

            Console.WriteLine($"Node value found: {found.Value}");

            Console.WriteLine($"Let's add a node before {found.Value}");
            list.AddBefore(new Node(26), found);
            list.Print();
            Console.WriteLine("-----");

            Console.WriteLine($"Let's add a node after {found.Value}");
            Console.WriteLine($"Node value found: {found.Value}");
            list.AddAfter(new Node(30), found);
            list.Print();
            Console.WriteLine("-----");

            Console.WriteLine("Lets add a node at the end");
            list.AddLast(new Node(1));
            list.Print();
        }
Beispiel #2
0
        /// <summary>
        /// method to make a linked list, print to screen, and find a selected value
        /// </summary>
        static void MakeLL()
        {
            LinkList LL = new LinkList(new Node(10));

            Node LL1 = new Node(15);
            Node LL2 = new Node(20);
            Node LL3 = new Node(25);

            LL.Add(LL1);
            LL.Add(LL2);
            LL.Add(LL3);

            LL.Print();

            Node addMeBefore = new Node(1);
            Node addMeAfter  = new Node(2);

            LL.Find(25);

            LL.AddBefore(addMeBefore, LL3);
            LL.AddAfter(addMeAfter, LL2);

            LL.Print();
            //expected output 1-- 25 -- 20 -- 2 -- 15 -- 10
        }
        static void TestLL()
        {
            LinkList ll = new LinkList(new Node(10));

            ll.Add(new Node(15));
            ll.Add(new Node(20));

            ll.Print();

            //20 -> 15 -> 10
        }
         public static void kthElement()
        {
            LinkList ll = new LinkList(new Node(1));
            ll.Add(new Node(3));
            ll.Add(new Node(8));
            ll.Add(new Node(2));

            ll.Print();

            Node kEth = ll.KthElementFromEnd(2);
            Console.WriteLine($"The K element is {kEth.Value}.");
        }
        /// <summary>
        /// This tests if new nodes will be added
        /// </summary>
        public static void TestLL()
        {
            LinkList ll = new LinkList(new Node(10));

            ll.Add(new Node(15));
            ll.Add(new Node(20));

            ll.Print();
            //20 -> 15 -> 10

            Console.WriteLine("Let's find Node 10");

            Node found = ll.Find(10);

            Console.WriteLine(found.Value);
        }