1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| #include"stdio.h" #include "stdlib.h" #define NULL 0 #define LEN sizeof(struct node) typedef int datatype; typedef struct node { datatype data; struct node *next; }linklist; linklist *hrear_creat() { int x; linklist *head,*p,*rear; head=(struct node*)malloc (LEN); head->data=-999; rear=head; printf("请输入以整数0结束符"); scanf("%d,&x"); while(x!=0) { p=(struct node*)malloc(LEN); p->data=x; rear->next=p; rear=p; scanf("%d",&x); } rear->next=NULL; return(head); } int main() { linklist *hrear_creat(); return 0; }
|