学生信息链表,建立,插入,删除,遍历,查找,修改,最大(小)值,平均...
/【例11-10】建立一個學生成績信息(包括學號、姓名、成績)的單向鏈表,學生數據按學號由小到大順序排列,要求實現對成績信息的插入、修改、刪除和遍歷操作。/
/* 用鏈表實現學生成績信息的管理 */
include<stdio.h>
include<stdlib.h>
include<string.h>
struct stud_node{
int num;
char name[20];
int score;
struct stud_node next;
};
struct stud_node Create_Stu_Doc(); /* 新建鏈表 /
struct stud_node InsertDoc(struct stud_node * head, struct stud_node stud); / 插入 /
struct stud_node DeleteDoc(struct stud_node * head, int num); /* 刪除 /
void Print_Stu_Doc(struct stud_node head); /* 遍歷 */
struct stud_node * Find(struct stud_node * head, int num); /查找/
struct stud_node * Modify(struct stud_node * head, int num, int score); /修改成績/
struct stud_node * Max(struct stud_node * head); /求最高分數的學生記錄/
struct stud_node * Min(struct stud_node * head); /求最低分數的學生記錄/
double Ave(struct stud_node * head); /求平均分/
void Save(struct stud_node * head);
struct stud_node *Read();
typedef struct stud_node *LNode;
LNode head,p;
int main(void)
{
struct stud_node head=NULL, p;
int choice, num, score;
char name[20];
int size = sizeof(struct stud_node);
do{
printf("1:Create 2:Insert 3:Delete 4:Print 5:Modify 6:Find 7:Max 8:Save 9:Read 10:Min 0:Exit\n");
scanf("%d", &choice);
switch(choice){
case 1:
head = Create_Stu_Doc();
break;
case 2:
printf("Input num,name and score:\n");
scanf("%d%s%d", &num,name, &score);
p = (struct stud_node *) malloc(size);
p->num = num;
strcpy(p->name, name);
p->score = score;
head = InsertDoc(head, p);
break;
case 3:
printf("Input num:\n");
scanf("%d", &num);
head = DeleteDoc(head, num);
break;
case 4:
Print_Stu_Doc(head);
break;
case 5:
printf("Input num:\n");
scanf("%d", &num);
printf("Input score:\n");
scanf("%d", &score);
head=Modify(head,num,score);
break;
case 6:
printf("Input num:\n");
scanf("%d", &num);
p=Find(head,num);
if(p!=NULL)
printf("%d\t%s\t%d \n", p->num, p->name, p->score);
else
printf("Not Found %d\n",num);
break;
case 7:
p=Max(head);
if(p!=NULL)
printf("%d\t%s\t%d \n", p->num, p->name, p->score);
else
printf("Not Found\n");
break;
case 8:
Save(head);
break;
case 9:
head=Read();
break;
case 10:
p=Min(head);
if(p!=NULL)
printf("%d\t%s\t%d \n", p->num, p->name, p->score);
else
printf("Not Found\n");
break;
case 0:
break;
}
}while(choice != 0);
return 0;
}
/新建鏈表/
struct stud_node * Create_Stu_Doc()
{
struct stud_node * head,*p;
int num,score;
char name[20];
int size = sizeof(struct stud_node);
}
return head;
}
/* 插入操作 /
struct stud_node InsertDoc(struct stud_node * head, struct stud_node stud)
{
struct stud_node ptr ,ptr1, ptr2;
}
/* 刪除操作 /
struct stud_node DeleteDoc(struct stud_node * head, int num)
{
struct stud_node ptr1, ptr2;
}
/遍歷操作/
void Print_Stu_Doc(struct stud_node * head)
{
struct stud_node * ptr;
}
struct stud_node * Find(struct stud_node * head, int num) /查找/
{
struct stud_node *ptr;
}
struct stud_node * Modify(struct stud_node * head, int num, int score)/修改通過查找學號修改成績/
{
struct stud_node *ptr;
}
struct stud_node * Max(struct stud_node * head)
{
struct stud_node maxp,ptr;
}
struct stud_node * Min(struct stud_node * head)
{
struct stud_node minp,ptr;
}
void Save(struct stud_node * head)
{
FILE fp;
if((fp=fopen("data.txt","w")) == NULL){ /打開文件(套用)*/
printf("File open error!\n");
exit(0);
}
}
struct stud_node Read()
{
FILE fp;
if((fp=fopen("data.txt","r")) == NULL){
printf("File open error!\n");
exit(0);
}
}
if( fclose(fp) ){printf( "Can not close the file!\n" );exit(0); }return head;}
轉載于:https://www.cnblogs.com/1112zx/p/10549694.html
總結
以上是生活随笔為你收集整理的学生信息链表,建立,插入,删除,遍历,查找,修改,最大(小)值,平均...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第六章 SpringCloud之Ribb
- 下一篇: 云笔记项目-过滤器与拦截器学习