创建链表和输出链表 怎么就不对呢
程序代码:
#include <stdio.h> #include <malloc.h> struct date { unsigned int month; unsigned int day; unsigned int year; struct date* next; }; int main(int argc, char* argv[]) { struct date* head; struct date* p; p=(struct date*)malloc(sizeof(struct date)); p->next=NULL; head=p; int i; for(i=0;i<3;i++) { p=(struct date*)malloc(sizeof(struct date)); scanf("%u%u%u",&p->month,&p->day,&p->year); p->next=NULL; } p=head; while(p!=NULL) { printf("%4u%2u%2u\n",p->year,p->month,p->day); p=p->next; } free(p); return 0; }
抛开资料 自己默写 就写不对 不知道差在哪里