删除单链表中的重复结点
发布时间
阅读量:
阅读量
设计一个函数,用于移除单链表中重复的节点。例如,若原始链表中的节点依次为3、5、1、3、6、7、3、9,则在删除重复节点后,链表中的节点应依次为3、5、1、6、7、9。
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int data;
node *next;
}Node;
/*链表创建*/
Node *Creat()
{
Node *head,*tail,*p;
int x;
head=(Node *)malloc(sizeof(Node));
head->next=NULL;
tail=head;
scanf("%d",&x);
while(x!=0)
{
p=(Node *)malloc(sizeof(Node));
if(p==NULL)
{
printf("空间分配失败");
return NULL;
}
p->data=x;
p->next=NULL;
tail->next=p;
全部评论 (0)
还没有任何评论哟~
