/*-----------利用尾插法建立一个含有头结点的非循环单链表----------*/
#include <iostream.h>
#define ok 1;
#define error 0;
typedef int elemtype;
typedef struct lnode{
lnode *next;
elemtype data;
} lnode,*linklist;
bool createlist(linklist &h,int n){
linklist p,q;
h=new lnode;
h->next=NULL;
q=h;
cout<<"input data:"<<endl;
if(n<0) return error;
for(int i=0;i<n;i++){
p=new lnode;
cin>>p->data;
p->next=q->next;
q->next=p;
q=q->next;
}
return ok;
}
bool printlist(linklist h){
linklist p;
p=h->next;
while(p!=NULL){
cout<<p->data<<' ';
p=p->next;
}
return ok;
}
void main(){
linklist h;
int n;
cout<<"lnodes number:";
cin>>n;
createlist(h,n);
printlist(h);
}