Skip to content

Instantly share code, notes, and snippets.

@Mahdhir
Created May 2, 2020 13:16
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/f8327898c22908e4b718d392471fb337 to your computer and use it in GitHub Desktop.
Save Mahdhir/f8327898c22908e4b718d392471fb337 to your computer and use it in GitHub Desktop.
public void insertAfter(Node prev_node, int new_data) {
if (prev_node == null) {
System.out.println("The given previous node cannot be null");
return;
}
Node new_node = new Node(new_data);
new_node.next = prev_node.next;
prev_node.next = new_node;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment