高手帮我改下程序,关于动态链表
要求是输入一串数字,按大小依次存入自定义的链表中,以输入0结束,最后输出链表#include <iostream>
using namespace std;
#define NULL 0
int main()
{struct shu
{
long num;
shu *next;
};
cout<<"input the num:";
int n;
shu *p0,*p1,*p2,*p;
shu *head;
head=NULL;
p0=new shu;
cin>>p0->num;
p1=head;
while(p0->num!=0)
{
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
else
{
while ((p0->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->num<p1->num)
{
if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
n=n+1;
}
cout<<"there are:";
p=head;
do
{
cout<<p->num<<" ";
p=p->next;
}
while(p!=NULL);
return 0;
}