#include
using namespace std;
typedef struct Node
{
int age;
struct Node* next;
}LIST;
LIST* CreatList()
{
int data=0;
LIST* Phead=NULL;
LIST* Pm=NULL;
LIST* Pcur=NULL;
Phead=(LIST*)malloc(sizeof(LIST));
Phead->age=0;
Phead->next=NULL;
cout<<"Enter your data of node (-1 quit):";
scanf("%d", &data);
Pcur=Phead;
while (data!=-1)
{
Pm=(LIST*)malloc(sizeof(LIST));
Pm->age=data;
Pm->next=NULL;
Pcur->next=Pm;
Pcur=Pcur->next;
cout<<"Enter your data of node (-1 quit):";
scanf("%d", &data);
}
return Phead;
}
void ListOut(LIST* Phead)
{
LIST* p=NULL;
if(Phead==NULL) //如果改为if(Phead->next==NULL)则cout执行,why?
{
cout<<"List is NULL\n";
}
else
{
p=Phead->next;
while(p!=NULL)
{
cout<<p->age<<endl;
p=p->next;
}
}
}
void main()
{
LIST* p1=CreatList();
ListOut(p1);
system("pause");
}