Created
May 2, 2020 13:17
-
-
Save Mahdhir/01962a0b578c9bf10cb3b4c02c4fa381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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