数据结构作业 用c语言建立一个存储学生数据的单链表 链表中节点数据域由学号年龄成绩构成 20
2个回答
展开全部
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
int main(void)
{
struct student
{
int age;
double score;
char name[20];
char studentNumber[20;]
struct student *next;
};
struct student *first=NULL;
struct student *current=NULL;
struct student *last=NULL;
char test='\0';
for( ; ; )
{
printf(" (Y=继续 or N=取消)?");
scanf(" %c",&test);
if(tolower(test)=='n')
break;
current=(struct student*) malloc (sizeof (struct student) );
if(first==NULL)
{
first=current;
}
else
{
last->next=current;
}
printf("\n student Name(输入学生姓名) :");
scanf("%s",current->name);
printf("\n student Name(输入学生学号) :");
scanf("%s",current->studentNumber);
printf("\n student age(学生年龄):");
scanf("%d",¤t->age);
printf("\nstudent score(分数):");
scanf("%ld",¤t->score);
current->next=NULL;
last=current;
}
printf(" \n \n \t");
printf("姓名 学号 年龄 分数 " );
current=first;
while(current!=NULL)
{
printf("\t--------------------------------\n");
printf("\t%-s %10s %5d %5.2ld \n",
current->name,current->studentNumber,
current->age,current->score);
last=current;
current=current->next;
free(last);
}
return(0);
}
#include<ctype.h>
#include<stdlib.h>
int main(void)
{
struct student
{
int age;
double score;
char name[20];
char studentNumber[20;]
struct student *next;
};
struct student *first=NULL;
struct student *current=NULL;
struct student *last=NULL;
char test='\0';
for( ; ; )
{
printf(" (Y=继续 or N=取消)?");
scanf(" %c",&test);
if(tolower(test)=='n')
break;
current=(struct student*) malloc (sizeof (struct student) );
if(first==NULL)
{
first=current;
}
else
{
last->next=current;
}
printf("\n student Name(输入学生姓名) :");
scanf("%s",current->name);
printf("\n student Name(输入学生学号) :");
scanf("%s",current->studentNumber);
printf("\n student age(学生年龄):");
scanf("%d",¤t->age);
printf("\nstudent score(分数):");
scanf("%ld",¤t->score);
current->next=NULL;
last=current;
}
printf(" \n \n \t");
printf("姓名 学号 年龄 分数 " );
current=first;
while(current!=NULL)
{
printf("\t--------------------------------\n");
printf("\t%-s %10s %5d %5.2ld \n",
current->name,current->studentNumber,
current->age,current->score);
last=current;
current=current->next;
free(last);
}
return(0);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询