-
-
Save Preetiraj3697/05e7c342052ad696900b0c9ced6725f0 to your computer and use it in GitHub Desktop.
Delete node in a Linked List from a specified position
This file contains hidden or 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
const LinkedListNode = class { | |
constructor(nodeData) { | |
this.data = nodeData; | |
this.next = null; | |
} | |
}; | |
// Complete the function below | |
function deleteNode(head, position) { | |
if(position==0){ | |
return head.next | |
} | |
head.next = deleteNode(head.next,position-1) | |
return head; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Deleting a Node -60:42:7
Description
Delete the node at a given position in a linked list and return a reference to the head node. The head is at position 0. The list may be empty after you delete the node. In that case, return a null value.
Complete thedeleteNodefunction in the editor below.
deleteNodehas the following parameters:
-LinkedListNode pointer list:a reference to the head node in the list
-int position:the position of the node to remove