public void CanAddNode()
        {
            // Arrange
            LinkList ll    = new LinkedLists.LinkList(new Node(4));
            Node     node  = new Node(8);
            Node     node2 = new Node(15);

            // Act
            ll.Add(node);
            ll.Add(node2);

            /*
             * 15 <- 8 <- 4
             */

            //Assert
            Assert.Equal(ll.Head.Value, node2.Value);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            LinkList newLinked = new LinkList();

            string userInput = "";

            while (userInput != "6")
            {
                Console.WriteLine("1. Show Head");
                Console.WriteLine("2. Add Item");
                Console.WriteLine("3. Remove Item");
                Console.WriteLine("4. Search for Item");
                Console.WriteLine("5. Print");
                Console.WriteLine("6. Exit\n");

                userInput = Console.ReadLine();

                switch (userInput)
                {
                case "1":
                    // show first item in list
                    if (newLinked.getFirst() == null)
                    {
                        Console.WriteLine("Empty List\n");
                    }
                    else
                    {
                        Console.WriteLine(newLinked.getFirst().data);
                    }
                    break;

                case "2":
                    // add item to list
                    Console.WriteLine("What would you like to add?\n");
                    string addedLink = Console.ReadLine();

                    Console.WriteLine("Would you like to add to the front or back of the list? 'F'= Front/'B' = Back\n");
                    string frontBack = Console.ReadLine().ToUpper();
                    while (!frontBack.Equals("B") && !frontBack.Equals("F"))
                    {
                        Console.WriteLine("Pick a valid option\n");
                        frontBack = Console.ReadLine().ToUpper();
                    }
                    if (frontBack.Equals("F"))
                    {
                        newLinked.addFirst(addedLink);
                    }
                    else
                    {
                        newLinked.Add(addedLink);
                    }
                    break;

                case "3":
                    // remove item from list
                    Console.WriteLine("What would you like to remove?\n");
                    string removedLink = Console.ReadLine();
                    if (newLinked.Contains(removedLink) == null)
                    {
                        Console.WriteLine(removedLink + " does not exist in the list.\n");
                    }
                    else
                    {
                        newLinked.Remove(removedLink);
                        Console.WriteLine(removedLink + " removed from the list.\n");
                    }
                    break;

                case "4":
                    // search for specific item in list
                    Console.WriteLine("What would you like to look for?\n");
                    string searchedLink = Console.ReadLine();
                    if (newLinked.Contains(searchedLink) == null)
                    {
                        Console.WriteLine(searchedLink + " does not exist in the list.\n");
                    }
                    else
                    {
                        Console.WriteLine(searchedLink + " exists in the list.\n");
                    }

                    break;

                case "5":
                    // list all items
                    Console.WriteLine("Items in list are:");
                    Console.WriteLine(newLinked.PrintAllNodes());
                    break;

                case "6":
                    // exit program
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Please pick a valid option.\n");
                    break;
                }
            }
        }