本文共 447 字,大约阅读时间需要 1 分钟。
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->eResult: 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;}注意:这里不能处理最后一个节点的情况
转载地址:http://fbyab.baihongyu.com/