链表做法
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct no
{
int data;
struct no *next;
} node;
node *creat(int n)
{
node *head,*p,*tail;
head=(node *)malloc(sizeof(node));
head->next=NULL;
tail=head;
for(int i=1; i<=n; i++)
{
p=(node *)malloc(sizeof(node));
scanf("%d",&p->data);
p->next=NULL;
tail->next=p;
tail=p;
}
return head;
}
node *del(node *head)
{
node *p,*q,*k;
p=head->next;
while(p)
{
k=p;
q=p->next;
while(q)
{
if(p->data==q->data)
{
k->next=q->next;
free(q);
q=k->next;
}
else
{
k=q;
q=q->next;
}
}
p=p->next;
}
return head;
}
node *print(node *p)
{
node*q;
q=p->next;
while(q)
{
if(q->next==NULL)
{
printf("%d\n",q->data);
}
else
{
printf("%d ",q->data);
}
q=q->next;
}
return 0;
}
int main()
{
node *p;
int n,m;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
p=creat(m);
del(p);
print(p);
}
}