求大神,这个程序最后多输出了一次,想了很久也没想出来[em06]请问如何改呀
#include<iostream>using namespace std;
typedef int Elem;
typedef struct aaaa
{
Elem data;
struct aaaa *next;
}lian;
void main()
{
lian *head,*s,*p;
int x;
head=(lian*)malloc(sizeof(lian));
p=head;
while(x!=0)
{
cin>>x;
s=(lian*)malloc(sizeof(lian));
s->data=x;
p->next=s;
p=s;
}
head=head->next;
free(p);
while(head->next!=NULL)
{
cout<<head->data<<endl;
head=head->next;
}
}