关于链表的一个问题,无法改变值??
http://topic.csdn.net/u/20120728/21/1ee56666-32b5-452b-a3c8-981f79048fa0.html?72670
在看到上面的帖子的问题,有了以下的回答后,我自己也跑了下程序 改成这样
#include <stdio.h>#include <stdlib.h>#include <malloc.h>typedef struct LNode{ int data; struct LNode *next;}LNode,*LinkList;void CreateList(LinkList L, int n){ int i; LNode *p; p=(LinkList)malloc(sizeof(LNode)); if(!L) exit(0); L->next = NULL; for(i=n;i>0;i--) { p=(LNode *)malloc(sizeof(LNode)); if(!p) exit(0); scanf("%d",&p->data); p->next = L->next; L->next = p; }}int main(){ LinkList p; CreateList(p,10); return 0;}#include <stdio.h>#include <stdlib.h>#include <malloc.h>typedef struct LNode{ int data; struct LNode *next;}LNode,*LinkList;void CreateList(LinkList L, int n){ int i; LNode *p; if(!L) exit(0); L->next = NULL; for(i=n;i>0;i--) { p=(LNode *)malloc(sizeof(LNode)); if(!p) exit(0); scanf("%d",&p->data); p->next = L->next; L->next = p; }}int main(){ LinkList p; p=(LinkList)malloc(sizeof(LNode)); CreateList(p,10); return 0;}