数据结构课学到东西 在上机课只实现一小部分,因为没带电脑其余部分以后用c++全部写出来再发一次
头文件部分 head.h
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
struct zhifu
{
int no;
char name[20];
char sex[5];
int english;
int math;
int total;
float average;
struct zhifu *next;
};
char test='\0';
struct zhifu *first = NULL;
struct zhifu *ing = NULL;
struct zhifu *previous = NULL;
void bulid()
{
for(;;)
{
printf("\n你想继续输入学生数据吗(Y or N)?\n");
scanf("%c",&test);
getchar();
if(tolower(test)=='n')
break;
ing=(struct zhifu*)malloc(sizeof(struct zhifu));
if(first==NULL)
first =ing;
if(previous!=NULL)
previous->next=ing;
printf("\n这是第几学号学生的数据:");
scanf("%d",&ing->no);
printf("\n请定义学号为%d的学生姓名:",ing->no);
scanf("%s",ing->name);
printf("\n请定义学号为%d次学生性别:",ing->no);
scanf("%s",ing->sex);
getchar();
ing->next=NULL;
previous=ing;
}
}
void show()
{if(ing!=NULL)
{
for (ing = first; ing != NULL; ing = ing->next)
{
printf("%d %s ", ing->no, ing->name);
printf("%s %d %d ",ing->sex,ing->english,ing->math);
printf("%d %f\n",ing->total,ing->average);
}
}
else
printf("\n没有内容,有待添加\n");
}
main部分
#include"head.h"
int main()
{
int www;
while(1)
{
printf("\n\tstudent's master\n");
printf("\t1.show_student\n");
printf("\t2.find_student\n");
printf("\t3.change_student\n");
printf("\t4.add_student\n");
printf("\t5.bulid_student\n");
printf("\t6.exit\n");
printf("\t\tplease input(1~6): ");
scanf("%d",&www);
switch(www){
case 1: show();break;
//case 2: find();
//case 3: change();
//case 4: add();
case 5: bulid();break;
case 6: return 0;break;
default: printf("\ninput erro,please input again\n");
}
}
}