public void AddToEnd(int data) { if (nextNode == null) { nextNode = new Node(data); } else { nextNode.AddToEnd(data); } }
static void Main(string[] args) { //creates a new Node with a head value of 7 Node myNode = new Node(7); // adds a new node in myNode by updating Nodes pointer value and creating a new node with the new data and new pointer // this is not scalable myNode.next = new Node(5); //better way is to use the new method AddToEnd myNode.AddToEnd(12); myNode.AddToEnd(15); // call print method myNode.Print(); }
public void AddToEnd(int data) { if (headNode == null) { headNode = new Node(data); } else { headNode.AddToEnd(data); } }
public void AddToEnd(int data) { if (next == null) //end of the list { next = new Node(data); } else { next.AddToEnd(data); } }
public void AddToEnd(string data) { if (next == null) { next = new Node(data); } else { next.AddToEnd(data); } }