Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node.
EXAMPLE
Input: the node ‘c’ from the linked list a->b->c->d->e
EXAMPLE
Input: the node ‘c’ from the linked list a->b->c->d->e
Result: nothing is returned, but the new linked list looks like a->b->d->e
编程之美上的题目,只需要删除该节点的后一个节点,并将后一个节点的data拷贝过来。
void delete_mid(Node* mid){
if(mid==NULL) return;
Node* p=mid->next;
if(p==NULL) return;
mid->next=p->next;
mid->data=p->data;
delete p;
}
注意:这里不能处理最后一个节点的情况