Skip to content

Instantly share code, notes, and snippets.

@Preetiraj3697
Forked from rahul4coding/deleteNode.js
Last active October 21, 2022 05:48
Show Gist options
  • Save Preetiraj3697/05e7c342052ad696900b0c9ced6725f0 to your computer and use it in GitHub Desktop.
Save Preetiraj3697/05e7c342052ad696900b0c9ced6725f0 to your computer and use it in GitHub Desktop.
Delete node in a Linked List from a specified position
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;
}
@Preetiraj3697
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment