Skip to content

Instantly share code, notes, and snippets.

@Mahdhir
Created May 2, 2020 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mahdhir/5499e3093e9d2998663e308c1d631be6 to your computer and use it in GitHub Desktop.
Save Mahdhir/5499e3093e9d2998663e308c1d631be6 to your computer and use it in GitHub Desktop.
public void insertAtEnd(int new_data) {
Node new_node = new Node(new_data);
if (head == null) {
head = new Node(new_data);
return;
}
new_node.next = null;
Node last = head;
while (last.next != null)
last = last.next;
last.next = new_node;
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment