Пример #1
0
 public bool remove()
 {
     if (head == null)
     {
         return(false);
     }
     else
     {
         var runner = head;
         while (runner.next.next != null)
         {
             runner = runner.next;
         }
         System.Console.WriteLine("Last node " + runner.next.value + " is being removed from the list");
         if (runner == head)
         {
             System.Console.WriteLine(runner.value + " is the head, and we are going to remove the head from the list");
             head = null;
             return(true);
         }
         runner.next = null;
         System.Console.WriteLine(runner.value + " is now the last node in the list.");
         return(true);
     }
 }
Пример #2
0
        public void add(string value)
        {
            SllNode newNode = new SllNode(value);

            if (head == null)
            {
                head = newNode;
                Console.WriteLine(newNode.value + " is the new node, and the head of the list!");
            }
            else
            {
                SllNode runner = head;
                while (runner.next != null)
                {
                    runner = runner.next;
                }
                runner.next = newNode;
                Console.WriteLine(runner.value + " has been added to the list!");
            }
        }
Пример #3
0
 public SinglyLinkedList()
 {
     head = null;
 }
Пример #4
0
 public SllNode(string value)
 {
     this.value = value;
     next       = null;
 }