Esempio n. 1
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
        }
Esempio n. 2
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();
        }
        /// <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);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            LinkList theList = new LinkList();      //make new list

            theList.InsertFirst(22, 2.99);
            theList.InsertFirst(44, 4.99);
            theList.InsertFirst(66, 6.99);
            theList.InsertFirst(88, 8.99);

            //theList.DisplayList();
            //while (!theList.IsEmpty())
            //{
            //    Link aLink = theList.DeleteFirst();  //delete link
            //    Console.Write("Deleted ");           //display it
            //    aLink.DisplayLink();
            //    Console.WriteLine();
            //}
            theList.DisplayList();                   //display list
            Link f = theList.Find(44);               //find item

            if (f != null)
            {
                Console.WriteLine("Found link with key " + f.iData);
            }
            else
            {
                Console.WriteLine("Cant find Link");
            }

            Link d = theList.Delete(66);    //delete item

            if (d != null)
            {
                Console.WriteLine("Deleted link with key " + d.iData);
            }
            else
            {
                Console.WriteLine("Can't delete Link");
            }
            theList.DisplayList();


            Console.ReadLine();
        } //end main