include <stdio.h>
//submit C++
struct Node{
int data;
Node *next;
};
void createList(Node *&head){
Node *t,*tail=head;
int x;
while(scanf("%d",&x)==1&&x){
t=new Node;
t->data=x;
t->next=tail->next;
tail->next=t;
tail=t;
}
}
void print(Node *&head){
Node *p=head->next;
while(p){
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}
int main(){
Node *head;
head=new Node;
head->next=NULL;
createList(head);
print(head);
return 0;
}
这里面函数createList我无法理解, tail=t;不是直接把tail->next=t;覆盖了吗?但删去就不对了,而且这个head->next为null啊,怎么能形成链表呢?