顺序表C语言实现学生管理系统代码
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
9.退出\n");
scanf("%d",&a);
switch(a)
{
case 1: L=initseq();
displayAll(L); break; case 2: printf("\n 输入插入的位置:\n"); scanf("%d",&i); res=insertElem(L,i); if(res==1) displayAll(L); break; case 3: printf("\n 输入删除数据的位置:"); scanf("%d",&i); res=deleteElem(L,i); if(res==1) displayAll(L); break; case 4: printf("\n 学生总数为%d:\n",lengthList(L)); break; case 5: printf("\n 输入查找的学号:"); scanf("%s",ch); locateElem(L,ch);break; case 6: printf("\n 输入要查找学生的位置:"); scanf("%d",&i); locateElemByplace(L,i);break; case 7: displayAll(L);break; case 8: insertsort(L);break; case 9: printf("已退出"); b=0; break; } } }
Seqlist *L; L=(Seqlist *)malloc(sizeof(Seqlist)); L->last=-1; Student *s; printf("\n input students score,when the no is #,it finishes"); s=inputdata(); while(s) {
printf("\n\t\t%s\t\t%s\t\t%d",L->data[i].sno,L->data[i].sname,L->data[i].score); i=i+1; } }
void display(Seqlist *L,int i) {
printf("\n\t\tno\t\tname\t\tscore\n"); printf("\n\t\t%s\t\t%s\t\t%d",L->data[i].sno,L->data[i].sname,L->data[i].score); } Student *inputdata() { Student s1; Student *s=&s1; char no[5]; printf("\ninput no:"); scanf("%s",no); if(no[0]=='#')
int len,i,j; len=L->last; for(i=0;i<=len;i++) {
L1->data[i]=L->data[i]; } L1->last=L->last; for(i=1;i<=len;i++) {
if(L1->data[i].score>L1->data[i-1].score) {
int main()
{
printf("\n\n==========================================\n");
printf("
顺序表学生成绩管理系统
\n ");
printf("\n\n==========================================\n");
Seqlist *L;
char ch[5];
int i,res,a,b=1;
while(b)
{
printf("\n\n");
printf("1.创建
2.指定位置插入 3.按位置删除\n");
printf("4.求学生总数 5.按学号查找 6.按位置查找\n ");
printf("7.显示所有学生 8.成绩排序
顺序表的学生管理系统 c 语言实现
#include<stdio.h> #include<malloc.h> #include<string.h> #define MAXSIZE 100 typedef struct {
int score; char sno[5]; char sname[5]; }Student; typedef struct { int last; Student data[MAXSIZE]; }Seqlist; void displayAll(Seqlist *L) { int i,n; i=0; n=L->last; printf("\n\t\tno\t\tname\t\tscore\n"); while(i<=n) {
s=inputdata(); L->last++; L->data[i-1]=*s; return 1; }
int deleteElem(Seqlist *L,int i ) {
int j,k; k=L->l Nhomakorabeast; if(i<1||i>k+1) {
printf("the delete place error."); return 0; } for(j=i;j<=k;j++) { L->data[j-1]=L->data[j]; } L->last--; return 1; } void locateElem(Seqlist *L,char ch[5]) { int i; for(i=0;i<=L->last;i++) if(strcmp(L->data[i].sno,ch)==0) { display(L,i); break; } } void locateElemByplace(Seqlist *L,int i) { display(L,i-1); } int lengthList(Seqlist *L) { return L->last+1; } void insertsort(Seqlist *L) { Seqlist *L1=(Seqlist *)malloc(sizeof(Seqlist)); Student temp;
return NULL; strcpy(s->sno,no); printf("\ninput name:"); scanf("%s",s->sname); printf("input score:"); scanf("%d",&s->score); return s; }
Seqlist *initseq() {
L->last++; L->data[L->last]=*s; s=inputdata(); } return L; } int insertElem(Seqlist *L,int i) //在第 i 个位置上插入 { int j,k; Student *s; k=L->last; if(L->last==MAXSIZE-1) { printf("\n----------overflow------------\n"); return 0; } if(i<1||i>k+2) { printf("the insert place error."); return 0; } for(j=k;j>=i-1;j--) { L->data[j+1]=L->data[j]; }
temp.score=L1->data[i].score; strcpy(temp.sno,L1->data[i].sno); strcpy(temp.sname,L1->data[i].sname); L1->data[i]=L1->data[i-1]; for(j=i-2;(temp.score>L1->data[j].score)&&(j>=0);j--) L1->data[j+1]=L1->data[j]; L1->data[j+1].score=temp.score; strcpy(L1->data[j+1].sno,temp.sno); strcpy(L1->data[j+1].sname,temp.sname); } } printf("\n 排序后为:"); displayAll(L1); }