《带表头结点单链表创建打印》由会员分享,可在线阅读,更多相关《带表头结点单链表创建打印(2页珍藏版)》请在金锄头文库上搜索。
#include #include typedef struct node int data;struct node *next; NODE; NODE *create() NODE *head,*q,*p;int a,n;head=(NODE*)malloc(sizeof(NODE);q=head;printf(“nInput number of the list: “);scanf(“%d“,if(n0)printf(“Input the list: “);while(n0)scanf(“%d“,p=(NODE*)malloc(sizeof(NODE);p-data=a;q-next=p;q=p;n-;q-next=NULL;return(head); void print(NODE *head) NODE *p;p=head-next;printf(“Output the list: “);while(p!=NULL)printf(“%3d“,p-data);p=p-next; main() NODE *a; a=create(); print(a); printf(“n“);