Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. /*
  2.  
  3. Write a function to delete a node (except the tail) in a singly linked list, given only
  4. access to that node.
  5.  
  6. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3,
  7. the linked list should become 1 -> 2 -> 4 after calling your function.
  8.  
  9. */
  10. /**
  11. * Definition for singly-linked list.
  12. * struct ListNode {
  13. * int val;
  14. * struct ListNode *next;
  15. * };
  16. */
  17. void deleteNode(struct ListNode* node) {
  18.  
  19. node->val = node->next->val;
  20. node->next = node->next->next;
  21.  
  22. /*
  23. struct ListNode* nextNode = node->next;
  24.  
  25. node->val = nextNode->val;
  26. node->next = nextNode->next;
  27.  
  28. free(nextNode);
  29. */
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement