struct Tnode
{
int value;
Tnode* next;
};
Tnode* unique(Tnode* head)
{
if (head == NULL || head->next == head)
return head;
Tnode*p, *q;
p = head;
q = head->next;
while (q != head)
{
while (p->value == q->value&&q != head)
{
p->next = q->next;
free(q);
q = p->next;
}
if (q == head)
break;
p = q;
q = q->next;
}
if (p->value == q->value)
{
p->next = q->next;
free(q);
return p;
}
else
return q;
}
1(头) -》2——》2——》3——》3——》1——》1(头) 去除以后的结果为:1——》2——》3,注意头尾的1也要去掉一个。