Very simple problem but there is only issue with the solution is if the node to be deleted is the last node in the linked list.
public static boolean deleteNode(LinkedListNode n)
{
if(n == null || n.next == null)
return false;
LinkedListNode next =n.next;
n.data =next.data;
n.next=next.next;
return true;
}
No comments:
Post a Comment