Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node.
这道题的意思是这样的,本来我们删除一个节点,需要将上一个节点的next指向这个节点的next,但是能,现在不能对上一个节点进行操作了,只能对这个节点进行操作。那么直接覆盖这个节点的内容就行了。
struct LinkNode
{
LinkNode * next;
int value;
}
void deleteMiddle(LinkNode * currentNode)
{
if (currentNode == NULL || currentNode->next == NULL)
return false;
LinkNode * next = currentNode->next;
currentNode->next = next->next;
currentNode->value = next->value;
delete next;
return true;
}