Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Pinterest
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Delete a Node in the Middle of a linked list, Given only access to that Node

Objec­tive: Write a pro­gram to Delete a Node in the Mid­dle of a linked list, Given only access to that Node

Exam­ple:

Original List : ->1->2->8->3->7->0->4
After Deleting the mid node (say 7) : ->1->2->8->3->0->4

Input: A Linked List and access to the node which needs to be deleted

Out­put: Linked list with deleted node

Approach:

  • Approach is tricky and simple
  • Copy the value of next node to the node which you want to delete
  • Delete the next node

Delete a Node in the Middle of a linked list, Given only access to that Node

Delete a Node in the Mid­dle of a linked list, Given only access to that Node

Com­plete Code:


Out­put:

Original List : ->1->2->8->3->7->0->4
Aftter Deleting the mid node (say 7) : ->1->2->8->3->0->4

You may also like...