C语言中,动态链表的流程图。拜托各位了 3Q
#include<stdio.h>#include<string.h>#include<stdlib.h>structstudent{intage;charname[20...
#include <stdio.h> #include <string.h> #include <stdlib.h> struct student { int age; char name[20]; struct student *next; }; typedef struct student STU_NODE; typesef STU_NODE *LIST; typedef short COUNT; int main(void) { LIST head =NULL,tmp=NULL,p=NULL; COUNT count=0; while(1) { tmp=(LIST)malloc(sizeof(STU_NODE)); if(tmp==NULL) { printf("mallco error\n"); return 1; } printf("enter your age:\n"); scanf("%d",&tmp->age); if(tmp->age==0) { p->next=NULL; break; } printf("enter your name:\n"); scanf("%s",tmp->name); count++; if(count==1) { head=tmp; p=tmp; } else { p->next=tmp; p=tmp; } } free(tmp); tmp=NULL; printf("output china:\n"); for(tmp=head;tmp!=NULL;tmp=tmp->next) { printf("age=%d\n",tmp->age); printf("name=%s\n",tmp->name); } getchar(); return 0; } } free(tmp); tmp=NULL; printf("output china:\n"); for(tmp=head;tmp!=NULL;tmp=tmp->next) { printf("age=%d\n",tmp->age); printf("name=%s\n",tmp->name); } getchar(); return 0; }
展开
1个回答
展开全部
这样改察隐应该就可以则陵了: #include <stdio.h> #include <string.h> #include <stdlib.h> struct student { int age; char name[20]; struct student *next; }; typedef struct student STU_NODE; //原来是typesef STU_NODE *LIST; typedef STU_NODE *LIST; typedef short COUNT; int main(void) { LIST head =NULL,tmp=NULL,p=NULL; COUNT count=0; while(1) { tmp=(LIST)malloc(sizeof(STU_NODE)); if(tmp==NULL) { printf("mallco error\n"败盯厅); return 1; } printf("enter your age:\n"); scanf("%d",&tmp->age); if(tmp->age==0) { p->next=NULL; break; } printf("enter your name:\n"); scanf("%s",tmp->name); count++; if(count==1) { head=tmp; p=tmp; } else { p->next=tmp; p=tmp; } } free(tmp); tmp=NULL; printf("output china:\n"); for(tmp=head;tmp!=NULL;tmp=tmp->next) { printf("age=%d\n",tmp->age); printf("name=%s\n",tmp->name); } //添加一个getchar(); getchar(); getchar(); return 0; }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询