Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use single linked list to realize Student Information Management system in C language

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how the C language uses a single linked list to realize the student information management system, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to know it.

The running result is shown in the figure:

1. Running interface

two。 Enter student information

3. Sort by total score

The code is as follows:

# define ERROR 0#define OK 1#define OVERFLOW-1 LNode,*LinkList;// typedef int ElemType;typedef int Status;#include#include#include#include#includetypedef struct {char name [20]; char snumber [20]; char sex [10]; int math; int chinese; int english;} student;typedef struct LNode {student data; struct LNode * next;} LNode,*LinkList;// single linked list initialization Status InitList (LinkList & L) {L = new LNode; L-> next = NULL; return OK } / / create a single linked list void CreateList (LinkList & L next=NULL n) {LinkList r; LinkList p; L = new LNode; L-> next=NULL; r = L; int i; for (I = 0 data.math,&p- > data.sex,&p- > data.chinese,&p- > data.math,&p- > data.english); / / scanf ("% d%d%d", & p-> data.chinese,&p- > data.math,&p- > data.english); p-> next=NULL R-> next=p; r = p;}} / Total score Statistics int GradeSum (LinkList L) {int sum; sum = (L-> data.chinese) + (L-> data.english) + (L-> data.math); return sum;} / / Statistics of all student information void BianLi (LinkList L) {LinkList p; p = L-> next; printf ("name\ t student number\ t language\ t mathematics\ t English\ n") While (p) {printf ("% s\ t% s\ t% s\ t", p-> data.name,p- > data.snumber,p- > data.sex); printf ("% d\ t% d", p-> data.chinese,p- > data.math,p- > data.english,GradeSum (p)); p = p-> next; printf ("\ n");}} / / sort by total score void OrderSum (LinkList & L) {LinkList pfocus Qtail; tail = NULL While ((L-> next- > next)! = tail) {p = L; Q = L-> next; while (Q-> next! = tail) {if (GradeSum (Q))

< GradeSum(q->

Next) {p-> next = Q-> next; Q-> next = Q-> next- > next; p-> next- > next = Q; Q = p-> next;} Q = Q-> next; p = p-> next;} tail = Q;} printf ("sorting is complete! \ n ");} / / sort according to the language void OrderChinese (LinkList & L) {LinkList pdhoreqposttail; tail = NULL; while ((L-> next- > next)! = tail) {p = L; Q = L-> next; while (Q-> next! = tail) {if ((Q-> data.chinese))

< (q->

Next- > data.chinese) {p-> next = Q-> next; Q-> next = Q-> next- > next; p-> next- > next = Q; Q = p-> next;} Q = Q-> next; p = p-> next;} tail = Q;} printf ("sort complete! \ n ");} / / sort by English void OrderEnglish (LinkList & L) {LinkList p next Q if; tail = NULL; while ((L-> next- > next)! = tail) {p = L; Q = L-> next; while (Q-> next! = tail) {if ((Q-> data.english)

< (q->

Next- > data.english) {p-> next = Q-> next; Q-> next = Q-> next- > next; p-> next- > next = Q; Q = p-> next;} Q = Q-> next; p = p-> next;} tail = Q;} printf ("sort complete! \ n ");} / / sort according to mathematics void OrderMath (LinkList & L) {LinkList p next Q if; tail = NULL; while ((L-> next- > next)! = tail) {p = L; Q = L-> next; while (Q-> next! = tail) {if ((Q-> data.math))

< (q->

Next- > data.math) {p-> next = Q-> next; Q-> next = Q-> next- > next; p-> next- > next = Q; Q = p-> next;} Q = Q-> next; p = p-> next;} tail = Q;} printf ("sort complete! \ n ");} / Delete the student information Status ListDelete (LinkList & L _ next; int I) {LinkList p; LinkList q; int j; p = L _ Tincj = 0; while ((p-> next) & & (jnext; + + j;} if (! (p-> next) | | (j > iMet 1) return ERROR; q = p-> next; p-> next = Q-> next; delete q; return OK;} void DeleteStudent (LinkList & L) {int i; printf (" Please enter the serial number of the student to be deleted\ n ") Scanf ("% d", & I); ListDelete (Lmemi); printf ("deleted! \ n ");} / / insert student information Status ListInsert (LinkList & L int igradchar name [], char snumber [], char sex [], int chinese,int math,int english) {LinkList p = L; LinkList s; int j = 0; while (p & (jnext; + + j;} if (! p | j > imur1) return ERROR; s = new LNode; strcpy (s-> data.name,name); strcpy (s-> data.snumber,snumber); strcpy (s-> data.sex,sex); s-> data.chinese = chinese S-> data.math = math; s-> data.english = english; s-> next = p-> next; p-> next = s; return OK;} void InsertStudent (LinkList & L) {int n; char name [20], snumber [20], sex [10]; int chinese,math,english; printf ("Please enter position N:"); scanf ("% d", & n) Printf ("Please enter the student's name, student number, gender, Chinese score, math score, English score and total score in turn\ n"); scanf ("% s%s%s%d%d%d", & name,&snumber,&sex,&chinese,&math,&english); ListInsert (LMagne namephatemsnumberchinese English);} void menu () {printf ("\ t\ t\ t = =\ n\ n") Printf ("\ t\ t\ t student information management system\ n\ n"); printf ("\ t\ t\ t =\ n\ n"); printf ("\ t\ t\ t = system function menu =\ n") Printf ("\ t\ t\ t"-"\ n") Printf ("\ t\ t\ t"); printf ("\ t\ t =\ n"); printf ("\ t\ t" 0. Enter student information. Statistics on students\ n "); printf ("\ t\ t\ t =\ n "); printf ("\ t\ t "2. Sorted according to the total score. Sorted by Chinese scores, printf ("\ t\ t = =\ n"); printf ("\ t\ t 4. Rank 5 according to math scores. Sorted by English scores\ n "); printf ("\ t\ t\ t =\ n "); printf ("\ t\ t 6. " Delete student information 7. Insert student information "\ n"); printf ("\ t\ t\ t =\ n"); printf ("\ t\ t" 8. Exit system\ n "); printf ("\ t\ t\ t = =\ n "); printf ("\ t\ t--\ n "); printf ("\ n\ n\ n ");} void luRu (LinkList & L) {int n Printf ("Please enter the number of students N:"); scanf ("% d", & n); printf ("Please enter the student's name, student number, gender, Chinese score, math score, English score, total score\ n"); CreateList (LMagne); printf ("Student information has been entered!" Void main (int args,char argv []) {LinkList p; InitList (p); int i; do {menu (); scanf ("% d", & I); getchar (); switch (I) {case 0:luRu (p); break; case 1:BianLi (p); break; case 2:OrderSum (p); BianLi (p); break; case 3:OrderChinese (p); BianLi (p); break; case 4:OrderMath (p); BianLi (p); break Case 5:OrderEnglish (p); BianLi (p); break; case 6: DeleteStudent (p); break; case 7:InsertStudent (p); break; case 8:exit (0);}} while (I! =-1) } Thank you for reading this article carefully. I hope the article "how to use single linked list to implement student information management system in C language" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report