Delete Middle Node
EXAMPLE
Input: the node c from the linked list a - >b- >c - >d - >e- >f
Result: nothing is returned, but the new linked list looks like a - >b- >d - >e->fNode *del_midpoint(Node *head) {
Node *slow, *fast, *prev;
slow = fast = head;
prev = nullptr;
if (!head) return slow;
int count = 0;
while (fast) {
prev = slow;
slow = slow->next;
while (count < 2 && fast) {
fast = fast->next;
count++;
}
count = 0;
}
prev->next = slow->next;
delete slow;
}Last updated