您的位置:首页 > 其它

编码实现环状单向链表(尾指针直接指向头指针,中间没有空节点),去除连续的重复元素的操作

2014-05-13 22:29 501 查看
转载 http://blog.csdn.net/chivalrousli/article/details/25654493
比如:1(头)->2->2->3->3->1->1(头) 去除以后的结果为1->2->3,注意头尾的1也要去掉一个。
struct node
{
int data;
node* next;
};

node* uniquelist(node* head)
{
if(head==NULL||head->next==head)
return head;
node* p,*q;
p=head;
q=head->next;
while(q!=NULL)
{
while(p->data==q->data&&q!=head)
{
p->next=q->next;
free(q);
q=p->next;
}
if(q==head) break;
p=q;
q=q->next;
}
if(p->data==q->data)
{
q->next=q->next;
free(q);
return p;
}
else return q;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐