You are viewing a single comment's thread. Return to all comments →
INCLUDE INCLUDE SinglyLinkedListNode* deleteNode(SinglyLinkedListNode* llist, int position) {
SinglyLinkedListNode*ptr=llist; if (position==0) { return llist->next; } position=position-1; if (llist==NULL) { return llist;
} while (position--){ ptr=ptr->next; } SinglyLinkedListNode*privious=ptr; ptr=ptr->next; privious->next=ptr->next; // free(ptr); delete ptr; return llist; }
Delete a Node
You are viewing a single comment's thread. Return to all comments →
INCLUDE INCLUDE SinglyLinkedListNode* deleteNode(SinglyLinkedListNode* llist, int position) {
SinglyLinkedListNode*ptr=llist; if (position==0) { return llist->next; } position=position-1; if (llist==NULL) { return llist;
} while (position--){ ptr=ptr->next; } SinglyLinkedListNode*privious=ptr; ptr=ptr->next; privious->next=ptr->next; // free(ptr); delete ptr; return llist; }