• + 0 comments

    My C++ deletion solution:

    SinglyLinkedListNode* deleteNode(SinglyLinkedListNode* llist, int position) {
        SinglyLinkedListNode* ptr = llist;
        
        if (position == 0) {
            SinglyLinkedListNode* ret = llist->next;
            delete llist;
            return ret;
        }
        
        for (int i = 0; i < position-1; i++) {
            ptr = ptr->next;
        }
        
        SinglyLinkedListNode* remove = ptr->next;
        ptr->next = remove->next;
        delete remove;
        
        return llist;
    }