#include <stdlib.h>
#include <stdio.h>
struct node
{
int data;
struct node *next;
};
int main()
{
int n, i;
scanf("%d", &n);
struct node *h, *p, *q;
h = (struct node *)malloc(sizeof(struct node ));
h -> next = NULL;
for(i = 0; i < n; i++)
{
p = (struct node *)malloc(sizeof(struct node ));
scanf("%d", &p -> data);
p -> next = h -> next;
h -> next = p;
}
p = h -> next;
printf("%d\n%d", n, p -> data);
p = p -> next;
while(p)
{
printf(" %d", p -> data);
p = p -> next;
}
printf("\n");
p = h -> next;
while(p)
{
q = p;
while(q -> next)
{
if(q -> next -> data == p -> data)
{
q -> next = q -> next -> next;
n--;
}
else q = q -> next;
}
p = p -> next;
}
p = h -> next;
printf("%d\n%d", n, p -> data);
p = p -> next;
while(p)
{
printf(" %d", p -> data);
p = p -> next;
}
printf("\n");
return 0;
}
SDUT - 2122 数据结构实验之链表七:单链表中重复元素的删除
猜你喜欢
转载自blog.csdn.net/Miracle_QSH/article/details/81699649
今日推荐
周排行