标签:
#include <stdio.h> #include <malloc.h> int length=0; struct ListNode { int val; struct ListNode *next; }; void make(struct ListNode* &list){ struct ListNode *tail=NULL; struct ListNode *pre=list; int v; while(scanf("%d",&v)==1){ if(length==0){ pre->val=v; pre->next=NULL; }else{ tail=(struct ListNode*)malloc(sizeof(struct ListNode)); tail->val=v; tail->next=NULL; pre->next=tail; pre=tail; } length++; } tail=NULL; } void pList(struct ListNode* list){ struct ListNode* p=list; while(p){ printf("%d\n",p->val); p=p->next; } } int main(){ struct ListNode* list; list=(struct ListNode*)malloc(sizeof(struct ListNode)); make(list); pList(list); return 0; }
标签:
原文地址:http://www.cnblogs.com/dick159/p/4922738.html