Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. /*
  2. Delete Node at a given position in a linked list
  3. Node is defined as
  4. struct Node
  5. {
  6. int data;
  7. struct Node *next;
  8. }
  9. */
  10. Node* Delete(Node *head, int position)
  11. {
  12. // Complete this method
  13. Node *temp = head;
  14. if(position == 0){
  15. head = head->next;
  16. return head;
  17. }
  18. Node *temp2 = head;
  19. for(int i = 0 ; i < position-1; i++){
  20. temp2 = temp2->next;
  21. }
  22. temp = temp2->next->next;
  23. temp2->next = temp;
  24. return head;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement