If only given the pointer to the node to be deleted? Note the node is not the first one nor the last.
如果在单链表中删除一个指定的结点? 需要注意的是不是头尾结点。
这到题其实就是个小技巧,没有告诉前面的一个结点怎么做删除呢?答案就是把后面结点的内容拷贝过来!这个问题的前提是结点不能使首尾结点,否则就没法做了。
假设数据内容是整型,简化问题。
void delete(Node p){
Node q = p.next;
p.data = q.data;
p.next = q.next;
}