#include "stdio.h" #include "malloc.h" typedef int elemtype; struct node { elemtype data; struct node *next; }; typedef struct node NODE; NODE * creat(NODE *head) { NODE *p,*q; elemtype i; head=(NODE*)malloc(sizeof(NODE)); scanf("%d",&(head->data)); p=head; while(p->data!=0)//0为结束符 { q=(NODE*)malloc(sizeof(NODE)); scanf("%d",&(q->data)); p->next=q; p=q; } p->next=NULL; return head; } void printlist(NODE *head) { NODE *p; elemtype i=0; p=head; while(p->next!=NULL) { printf("the %d node/n",i); i++; printf("%d/n",p->data); p=p->next; } printf("/n"); } void main(void) { NODE *my_head; my_head=(NODE *)malloc(sizeof(NODE)); my_head=creat(my_head); printlist(my_head); //getch(); }
posted on 2009-09-23 22:32 Hibernate4 阅读(129) 评论(0) 编辑 收藏 举报