#include <iostream>
#include <algorithm>
using namespace std;
typedef struct Node
{
int val,c;
Node *next;
}LST;
int cmp(int a,int b)
{
return a<b?1:0;
}
LST *mycreat(int n)
{
int i=0,a[1001];
int t=n;
while (t--)
{
scanf("%d",&a[i++]);
}
sort(a,a+n,cmp);
LST *head=NULL,*p=NULL,*sec=NULL;
head=(LST*)malloc(sizeof(LST));
p=head;
for (i=0;i<n;i++)
{
sec=(LST*)malloc(sizeof(LST));
sec->val=a[i];
if(p->val==sec->val) p->c=1;
p->next=sec;
p=sec;
}
p->next=NULL;
return head;
}
void myprint(LST *head)
{
int f=0;
LST *p;
p=head->next;
while(p!=NULL)
{
if(f==0&&p->c!=1)
{
printf("%d",p->val);
}
else if(p->c!=1)
{
printf(" %d",p->val);
}
f++;
p=p->next;
}
printf("\n");
return ;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
LST *head;
head=mycreat(n);
myprint(head);
}
return 0;
}
单链表中删除重复值
最新推荐文章于 2022-10-08 21:22:18 发布