#includeusing namespace std;struct node{ int d; struct node *next;};//定义结点node *build1()//头插法构造单链表{node *p;//指向新建结点node *head;//头指针head=NULL;p=head;int x;cin>>x; while(x!=-1) { p=new node; p->d=x; p->next=head; head=p; cin>>x; } return head; }node *build2()//尾插法构造单链表{ node *head;//头指针 node *p,*s;//p指向当前结点,s指向尾结点 head=NULL; p=head; s=head; int x; cin>>x; while(x!=-1) { p=new node; p->d=x; if(!head)head=p; else s->next=p; s=p; cin>>x; } if(s)s->next=NULL; return head;} int main(){ node *p; p=build2(); while(p!=NULL) { cout<<(p->d); p=p->next; } return 0;}