Skip to content

Instantly share code, notes, and snippets.

@Mahdhir
Created May 2, 2020 13:17
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/01962a0b578c9bf10cb3b4c02c4fa381 to your computer and use it in GitHub Desktop.
Save Mahdhir/01962a0b578c9bf10cb3b4c02c4fa381 to your computer and use it in GitHub Desktop.
void deleteNode(int position) {
if (head == null)
return;
Node temp = head;
if (position == 0) {
head = temp.next;
return;
}
// Find the key to be deleted
for (int i = 0; temp != null && i < position - 1; i++)
temp = temp.next;
// If the key is not present
if (temp == null || temp.next == null)
return;
// Remove the node
Node next = temp.next.next;
temp.next = next;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment