思路:用两对前驱和后继节点,分别比较当前节点的前驱和后继以及最小值界定啊的前驱和后继。 遍历完整个链表,删除最小值节点即可。
代码语言:javascript复制struct node {
int val;
node *next;
};
void deleteMin(node *head) {
node *p = head, *q = head->next;
node *premin = head, *pmin = head->next;
while (q) {
if (q->val < pmin->val) {
pmin = q;
premin = p;
p = p->next, q = q->next;
} else {
p = p->next;
q = q->next;
}
node *del = pmin;
premin->next = pmin->next;
delete del;
}
}