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); } }
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!"); } }
public SinglyLinkedList() { head = null; }
public SllNode(string value) { this.value = value; next = null; }