Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. /**
  2. * Problem: Implement an algorithm to delete a node in the middle of a single linked list,
  3. * given only access to that node.
  4. EXAMPLE
  5. Input: the node ā€˜cā€™ from the linked list a->b->c->d->e
  6. Result: nothing is returned, but the new linked list looks like a->b->d->e
  7. * Solution :- Copy content of the next node (both data and next into current node that way effectively deleting
  8. * next node
  9. */
  10. public class DeleteANodeFromSinglyLinkedList {
  11. public void deleteFromList(ListNode<Integer> nodeToDelete){
  12. nodeToDelete.data = nodeToDelete.next.data;
  13. nodeToDelete.next = nodeToDelete.next.next;
  14. }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement