C語言單鏈表實現(xiàn)學(xué)生管理系統(tǒng)
更新時間:2020年12月10日 16:41:11 作者:weixin_44859250
這篇文章主要為大家詳細介紹了C語言單鏈表實現(xiàn)學(xué)生管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了C語言單鏈表實現(xiàn)學(xué)生管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
代碼:
#include<stdio.h> #include<stdlib.h> #include <string.h> #include <malloc.h> struct Student { int num;//學(xué)號 char name[20];//名字 char sex[2]; int age; struct Student *next; }; void insert(struct Student **head); //插入 void print(struct Student *head); //遍歷所有鏈表 void dele(struct Student **head); //刪除 指定內(nèi)容 void modify(struct Student **head); // 修改內(nèi)容 void find(struct Student *head); //查找學(xué)生信息 int modify_menu(); int main() { struct Student *head = NULL; int x; do { printf("------------------------------------------\n"); printf(" 學(xué)生管理系統(tǒng) \n"); printf(" \n"); printf(" 1 增加學(xué)生 2 刪除學(xué)生 \n"); printf(" \n"); printf(" 3 修改資料 4 查找學(xué)生 \n"); printf(" \n"); printf(" 5 顯示所有學(xué)生 0 退出系統(tǒng) \n"); printf(" \n"); printf("------------------------------------------\n"); printf("請輸入你需要使用的功能\n"); scanf("%d",&x); switch(x) { case 0 : break; case 1 : insert(&head); break; case 2 : dele(&head); break; case 3 : modify(&head); break; case 4 : find(head); break; case 5 : print(head); break; default : printf ("選擇錯誤?。。n"); break; } }while(x); } void insert(struct Student **head) { struct Student *p = (struct Student*)malloc(sizeof(struct Student)); struct Student *stu=NULL; printf("num:"); scanf("%d",&(p->num)); printf("name:"); scanf("%s",(p->name)); printf("sex:"); scanf("%s",p->sex); printf("age:"); scanf("%d",&p->age); p->next=NULL; if(*head == NULL) { *head = p; } else { stu = *head; while(stu->next != NULL) { stu = stu->next; } stu->next = p; } } void print(struct Student *head) { printf("學(xué)號 名字 性別 年齡 \n"); while(head != NULL) { printf("%5d %10s %s %d\n",head->num,head->name,head->sex,head->age); head=head->next; } } void dele(struct Student **head) { char arr1[20]; struct Student *p1 = NULL;//指向要刪除的前一個結(jié)點 struct Student *p2 = *head;//指向要刪除的結(jié)點 printf("請輸入要刪除的學(xué)生\n"); scanf("%s",arr1); while(p2 != NULL) { if(p1==NULL&&strcmp(arr1,p2->name)==0) { *head = p2->next; free(p2); break ; } else if(strcmp(arr1,p2->name)==0) { p1->next = p2->next; free(p2); break ; } p1=p2; p2=p2->next; } print(*head); } void modify(struct Student **head) //修改 { char arr[20]; int x = 0; struct Student *p = *head; printf("請輸入需要修改資料的名字\n"); scanf("%s",arr); while(p!=NULL) { if(strcmp(arr,p->name) ==0) { printf("請選擇修改的內(nèi)容\n"); x = modify_menu(); printf("請輸入新的內(nèi)容\n"); switch(x) { case 1 : scanf("%d",&p->num); break; case 2 : scanf("%s",p->name); break; case 3 : scanf("%s",p->sex); break; case 4: scanf("%d",&p->age); break; default : printf ("選擇錯誤?。?!\n"); break; } print(*head); break ; } p=p->next; } } int modify_menu() //修改的菜單 { int choose = 0; printf ("-----------------------------------\n"); printf ("* 1 學(xué)號 2 姓名 *\n"); printf ("* 3 性別 4 年齡 *\n"); printf ("* 0 取消修改 *\n"); printf ("-----------------------------------\n"); scanf ("%d", &choose); return choose; } void find(struct Student *head) { char arr[20]; printf("請輸入學(xué)生姓名\n"); scanf("%s",arr); while(head!=NULL) { if(strcmp(arr,head->name)==0) { printf("學(xué)號 名字 性別 年齡 \n"); printf("%5d %10s %s %d\n",head->num,head->name,head->sex,head->age); } head=head->next; } }
推薦幾篇文章:
關(guān)于管理系統(tǒng)的更多內(nèi)容請點擊《管理系統(tǒng)專題》進行學(xué)習(xí)
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- C語言結(jié)構(gòu)體鏈表和指針實現(xiàn)學(xué)生管理系統(tǒng)
- 基于C語言實現(xiàn)學(xué)生管理系統(tǒng)
- c語言實現(xiàn)學(xué)生管理系統(tǒng)詳解
- C語言實現(xiàn)班級學(xué)生管理系統(tǒng)
- C語言不用鏈表完成學(xué)生管理系統(tǒng)(完整代碼)
- C語言實現(xiàn)學(xué)生管理系統(tǒng)
- C語言鏈表實現(xiàn)學(xué)生管理系統(tǒng)
- C語言實現(xiàn)簡單學(xué)生管理系統(tǒng)
- C語言學(xué)生管理系統(tǒng)源碼分享
- C語言實現(xiàn)簡易學(xué)生管理系統(tǒng)
相關(guān)文章
Qt實現(xiàn)邊加載數(shù)據(jù)邊顯示頁面的示例代碼
無論是MFC框架還是QT框架,實現(xiàn)加載數(shù)據(jù)的等待效果都是很麻煩的,不像WEB端輕輕松松一句代碼就搞定了。本文將通過Qt實現(xiàn)邊加載數(shù)據(jù)邊顯示頁面的功能,需要的可以參考一下2022-01-01C++高級數(shù)據(jù)結(jié)構(gòu)之優(yōu)先隊列
這篇文章主要介紹了C++高級數(shù)據(jù)結(jié)構(gòu)之優(yōu)先隊列,文章圍繞主題的相關(guān)資料展開詳細介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-05-05Qt串口通信開發(fā)之QSerialPort模塊簡單使用方法與實例
這篇文章主要介紹了Qt串口通信開發(fā)之QSerialPort模塊簡單使用方法與實例,需要的朋友可以參考下2020-03-03解析c++中參數(shù)對象與局部對象的析構(gòu)順序的詳解
本篇文章是對c++中參數(shù)對象與局部對象的析構(gòu)順序進行了詳細的分析介紹,需要的朋友參考下2013-05-05