关于双向链表的错误
程序代码:
#include<stdio.h> #include<malloc.h> typedef struct life { int date; struct life *qian,*hou; }LIFEO; LIFEO * jianlilianbiao(LIFEO *KK,int n) { KK=(LIFEO *)malloc(sizeof(LIFEO)); KK->qian=NULL; KK->hou=NULL; LIFEO *p0=KK,*p; if(p0==NULL) printf("内存分配错误"); int t; for(t=0;t<n;t++) { p=(LIFEO *)malloc(sizeof(LIFEO)); printf("输入数据"); scanf("%d",&p->date); p->qian=p0; p0->hou=p; p0=p; printf("%d\n",p0->date); } p0->hou=NULL; return KK; } void DisplayDList(LIFEO *L){ LIFEO *p=L->hou; while(p!=NULL ){ printf("%d\n",p->date); p=p->hou ; } } int main() { LIFEO *ttt; jianlilianbiao(ttt,5); DisplayDList(ttt); }
编译通过
到最后就弹出错误……