代码如下
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int data;
struct node* next;
}Node;
Node* initialization(){
Node* head;
head=(Node*)malloc(sizeof(Node));
head->next=NULL;
return head;
}
Node* clist(Node* head){
Node* s=head;
Node* t;
int data;
while(1){
scanf("%d",&data);
if(data==0){
break;
}
t=(Node*)malloc(sizeof(Node));
t->data=data;
s->next=t;
s=s->next;
}
s->next=NULL;
return head;
}
void getout(Node* head){
Node* p=head->next;
while(p->next){
if(p->data==p->next->data){
p->next=p->next->next;
}
else{
p=p->next;
}
}
}
void output(Node* head){
Node* p=head->next;
while(p){
printf("%d ",p->data);
p=p->next;
}
}
int main()
{
Node* head;
head=initialization();
clist(head);
// output(head);
getout(head);
output(head);
return 0;
}