学生信息管理系统(C语言)

以 “ 链式队列 " 为数据结构所编写的。

源代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define newNode (stu*)malloc(sizeof(stu))

typedef struct Student{
    char name[20];
    char id[20];
    struct Student *next;
}stu;

typedef struct p{
    struct Student *head,*tail;
}headnode;

void init(headnode *h){//初始化
    h->head=h->tail=NULL;
    return;
}

void add(headnode *h){//1、入队
    stu *p;
    p=newNode;
    p->next=NULL;
    printf("请输入学生的信息:\n");
    printf("姓名:"); scanf("%s",p->name);
    printf("学号:"); scanf("%s",p->id);
    if(h->head==NULL){//如果队列为空,新插入的结点为队列中唯一一个结点
        h->head=p;
        h->tail=p;
        return;
    }
    //队列不为空
    h->tail->next=p;
    h->tail=p;
    return;
}
/*
stu *pop(headnode *h){//2、出队
    stu *p;
    p=newNode;
    p=h->head;
    if(p!=NULL){h->head=h->head->next; return p;}
    else printf("学生已全部删除!\n");
    return NULL;
}
*/
node *pop(queue *q){
node *p;
p=q->head;
if(p==NULL) { printf("队列为空"); return q;}
q->front=p->next;
free(p);
if(q->front==NULL) q->rear=NULL;
return q;
}

int empty(headnode *h){
    return h->tail=h->head?1:0;
}

void print(headnode *h){//3、遍历
    for(stu *i=h->head; i!=NULL; i=i->next){
        printf("姓名:%s\n",i->name);
        printf("学号:%s\n",i->id);
    }
}

void xiugai(headnode *h){//4、修改
    char nu[20];
    int state;
    printf("请输入您要修改的学生学号:\n");
    scanf("%s",nu);
    stu *q=h->head;
    while(q!=NULL){
        if(strcmp(q->id,nu)==0){
            state=1;
            printf("请输入您要修改的信息选项:1.姓名 2.学号\n");
            int choose;
            scanf("%d",&choose);
            if(choose==1){
                    printf("请输入您要修改的名字:");
                	scanf("%s",q->name);
                	printf("修改名字成功!\n");
            }
            if(choose==2){
                    printf("请输入您要修改的学号:");
                	scanf("%s",q->id);
                	printf("修改学号成功!\n");
            }

        }
        q=q->next;
   }
   if(state==0)
   {
     printf("该生不存在\n");
   }
}

void find(headnode *h){//5、检索
    char nu[20];
    int state;
    printf("请输入学生学号:");
    scanf("%s",nu);
    stu *q=h->head;
    while(q!=NULL){
        if(strcmp(q->id,nu)==0){
            state=1;
            printf("姓名:%s\n",q->name);
            printf("学号:%s\n",q->id);
        }
        q=q->next;
    }
    if(state==0)
   {
     printf("该生不存在!\n");
   }
}

int main()
{
    printf("学生信息队列基本功能菜单\n");
    printf("==========================\n");
    printf("1.添加学生信息(入队)\n");
    printf("2.删除学生信息(出队)\n");
    printf("3.显示学生信息(遍历)\n");
    printf("4.修改学生信息(修改)\n");
    printf("5.查找学生信息(检索)\n");
    printf("6.退出学生信息队列操作\n");
    printf("==========================\n");
    //初始化队列
    headnode *h;
    h=newNode;
    init(h);
    while(1){
    printf("请选择功能:");
    int x;scanf("%d",&x);
    switch(x){
        case 1:add(h);break;
        case 2:{
            stu *q; q=pop(h);
            if(q!=NULL){
            printf("姓名:%s\n",q->name);
            printf("学号:%s\n",q->id);
            }
            break;
        }
        case 3:print(h);break;
        case 4:xiugai(h);break;
        case 5:find(h);break;
        case 6:printf("系统已退出!");exit(0);
        default:
            printf("请输入正确的选择:");
            break;
    }
    }
    return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值