Example #1
0
 public void AddEnd(int value)
 {
     if (next == null)
     {
         next = new Datas(value);
     }
     else
     {
         next.AddEnd(value);
     }
 }
Example #2
0
        /// I got cocky because it was easy to make the search method
        /// The seperate times I thought the method was good, but then I tested and it partially worked
        /// I feel like I had to cheese the method so many times:
        /// - I had to create 2 extra methods in the Datas class to re-add the values into the headNode
        ///     - Since I set the headNode to null, I had to create another variable to hold the old headNode value.
        ///      - This is not the most efficient way, but I was able to solve a problem I had, which feels good.
        /// But I think its fine now

        public void RemoveSpecificData(int value)
        {
            Console.WriteLine("\n...Searching for " + value + " in the list...");
            bool found = Search(value);

            Thread.Sleep(1500);

            if (found)
            {
                Console.WriteLine("\nThe number has been found\n");

                if (headNode.data == value)
                {
                    RemoveData();
                    return;
                }
                Datas old_head = headNode;
                Datas temp     = headNode;
                Datas rem      = headNode;
                headNode = null;
                while (rem.next != null)
                {
                    if (rem.data == value)
                    {
                        temp.next = temp.next.next;
                        break;
                    }
                    else
                    {
                        temp = rem;
                        rem  = rem.next;
                        if (temp == old_head)
                        {
                            headNode = new Datas(temp.data);
                        }
                        else
                        {
                            headNode.AddEnd(temp.data);
                        }
                    }
                }
                if (rem.next == null)
                {
                    temp.next = null;
                }
                headNode.AddRest(temp.next);
                Console.WriteLine("[" + value + "] has been removed");
            }
            else
            {
                Console.WriteLine("\nThis number is not in the list");
            }
        }