关于链表创建无错误但运行程序终止
关于链表创建无错误但运行程序终止程序代码:
#include <stdio.h> #include <stdlib.h> #define GoodType int typedef struct Good { GoodType num; struct Good *next; }LGood, *LinkedGood; LinkedGood GoodInit (LinkedGood L) { L = (LGood*) malloc (sizeof(LGood)); if (L==NULL) { printf ("没有足够内存空间!"); exit (0); } L->next = NULL; return L; } LinkedGood GoodInsert (LinkedGood L, GoodType e) { LGood* p; LGood* s; p = L; while (p->next) { p = p->next; } s = (LGood*) malloc (sizeof(LGood)); s->num = e; s->next = p->next; p->next = s; return L; } LinkedGood GoodPrintNum (LinkedGood L) { LGood* p; p = L->next; while (p!=NULL) { printf ("%d ", p->num); p = p->next; } return L; } void GoodRelease (LinkedGood L) { LGood* p; LGood* s; p = L; if (p==NULL) { printf ("空表!"); exit (0); } while (p!=NULL) { s = p; p = p->next; free (s); } } void main () { LinkedGood L; GoodInit (L); GoodInsert (L, 10); GoodPrintNum (L); GoodRelease (L); }