思路:定义两个指针cur和p来逐个遍历链表,cur元素依次和p比较,直到p为NULL,cur向后移动一个。
struct listnode* delete_double_node(struct listnode* H)
{
if(H==NULL) return NULL; //判断是否需要遍历
struct listnode* cur=H;
while(cur)
{
struct listnode* p=cur;
while(p->next)
{
if(p->next->data==cur->data)
{
p->next=p->next->next;
}else
{
p=p->next;
}
cur=cur->next;
}
}
return H;
}


京公网安备 11010502036488号