# C语言 链表 数据结构实验之链表七：单链表中重复元素的删除

### 数据结构实验之链表七：单链表中重复元素的删除

#### Example Input

10
21 30 14 55 32 63 11 30 55 30

#### Example Output

10
30 55 30 11 63 32 55 14 30 21
7
30 55 11 63 32 14 21
#include <stdio.h>
#include <stdlib.h>
struct sdut
{
int data;
struct sdut *next;
};
int main()
{
int n, i;
scanf("%d", &n);
struct sdut *head, *p, *q, *t;
head = (struct sdut*) malloc (sizeof(struct sdut));
for(i = 0; i < n; i++)
{
p = (struct sdut*) malloc (sizeof(struct sdut));
scanf("%d", &p -> data);
p -> next = head -> next;
}
printf("%d\n",n);
while(p)
{
if(p -> next)
{
printf("%d ", p -> data);
}
else
{
printf("%d\n", p -> data);
}
p = p -> next;
}
while(p -> next != NULL)
{
q = p -> next;
t = p;
while(q != NULL)
{
if(p -> data == q -> data)
{
q = q -> next;
t -> next = q;
n--;
}
else
{
q = q -> next;
t = t -> next;
}
}
if(p -> next == NULL)
{
break;
}
else
{
p = p -> next;
}
}
printf("%d\n",n);
while(p)
{
if(p -> next)
{
printf("%d ", p -> data);
}
else
{
printf("%d\n", p -> data);
}
p = p -> next;
}
return 0;
}