You are viewing a single comment's thread. Return to all comments →
Solution in C++:
SinglyLinkedListNode* deleteNode(SinglyLinkedListNode* llist, int position) { SinglyLinkedListNode* head = llist; SinglyLinkedListNode* ptr = llist; if(position) { for(int i = 0; i < position-1; ++i) { ptr = ptr->next; } SinglyLinkedListNode* to_remove = ptr->next; SinglyLinkedListNode* nxt = to_remove->next; delete to_remove; ptr->next = nxt; return head; } else { SinglyLinkedListNode* nxt = ptr->next; delete ptr; return nxt; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Delete a Node
You are viewing a single comment's thread. Return to all comments →
Solution in C++: