public void AddToEnd(int data) { if (headNode == null) { headNode = new Node(data); } else { headNode.AddToEnd(data); } }
public void AddToEnd(int data) { if (next == null) { next = new Node(data); } else { next.AddToEnd(data); } }
public void AddToEnd(int data) { if (headNode == null) { headNode = new Node(data); } else { //using recursion, method is calling itself until the condition is met headNode.AddToEnd(data); } }
public void AddToEnd(int data) { // In this case we know that this is the end of the list, so we just add a new Node! if (next == null) { next = new Node(data); } else { // recursive call (passa the responsibility down to the chain, until "next" == null)! next.AddToEnd(data); } }