// DATE:2006-11-20 BY:Snowhill
#include "iostream.h"
struct link
{
int data;
link *next;
};
//头插法建立链表,带头结点
link *hcreat()
{
link *p,*s;
int i;
cin>>i;
p=new link;
p->next=NULL;
while(i)
{
s=new link;
s->data=i;
s->next=p->next;
p->next=s;
cin>>i;
}
return p;
}
//create the node list with rear
link *rcreat()
{
link *s,*p,*r;
int i;
p=r=new link;//the p and r is head
p->next=NULL;
cout<<"thes adress of p->next is "<<p->next;
cin>>i;
while(i)
{
s=new link;
s->data=i;
r->next=s;
r=s;
cin>>i;
}
r->next=NULL;
cout<<"thes adress of r->next is "<<p->next;
return p;
}
//print the link node
void print(link *head)
{
link *p;
p=head->next;
while(p->next!=NULL)
{
cout<<p->data<<"->";
p=p->next;
}
cout<<p->data;
cout<<endl;
}
void main()
{
link *p;
p=rcreat();
print(p);
}