Delete a node in a Singly Linked List
  • node
  • singlylinkedlist
  • linkedlist
  • stackqueuelinkedlist
  • delete
  •   
  • Posted: 7 years ago
  • Edit
  • answers (1)
  • views (4055)

Write a function to delete a node from a Singly Linked List.


Posted Answers

public Node deleteNode(Node head, int d){
Node node = head;
if(node.data == d)
return head.next;

while(node.next! = null){
if(node.next.data == d){
node.next = node.next.next;
return head;
}
node = node.next;
}
}

You need to Sign In to post your solution.