比如 1->2->2->3,删除重复后,变为1->3。
void delDup(Node* head) { Node node; node.next = head; Node* n1, n2; n1 = node; n2 = node->next; int data; while (n2) { data = n2->data; n2 = n2->next; if (n2 && n2->data == data) { n2 = n2->next; } else { if (n1->next->next == n2) { n1 = n1->next; } else { n1->next = n2; } } } head = node.next; }
时间: 2024-11-09 05:10:08