In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use linked list in C language to realize the management system of students' place of origin". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn "how to use linked list in C language to realize student place management system".
The source code # include#include#include// defines a student structure typedef struct student {char no [12]; / / student ID char name [40]; / / name char tele [20]; / / telephone number int D [18]; / / telephone number char jg [60]; / / place of origin char addr [80] / / address struct student* next; / / pointer to the next node} STU;// function declaration is placed here STU* LIstInit (STU* L); STU* ListCreate (STU* L, int n); void ListInsert (STU* L); void ListDelete (STU* L, char n [40]); void LIstSearch (STU* L, char n []); void input (STU* p, int I); void output (STU* L); void menu () / / create the header, initialize the linked list STU* LIstInit (STU* L) {STU* head = NULL; head = (STU*) malloc (sizeof (STU)); head- > next = NULL; L = head; return L;} / / create the linked list, and insert the newly generated node into the header STU* ListCreate (STU* L, int n) {int i; for (I = 0; I) of the linked list
< n; i++) { STU* p; //将新生成的节点插入到链表中 p = NULL; p = (STU*)malloc(sizeof(STU)); input(p, i); p->Next = L-> next; L-> next = p;} return L;} / A pair of linked lists perform node insertion operation void ListInsert (STU* L) {STU* s = NULL; / / generate a new node s = (STU*) malloc (sizeof (STU)); printf ("Please enter the student number of the student you want to insert:"); scanf ("% s", & s-> no) Printf ("Please enter the name of the student you want to insert:"); scanf ("% s", & s-> name); printf ("Please enter the phone number of the student you want to insert:"); scanf ("% s", & s-> tele); printf ("Please enter the ID number of the student you want to insert:"); scanf ("% s", & s-> D) Printf ("enter the place of origin of the student you want to insert:"); scanf ("% s", & s-> jg); printf ("Please enter the mailing address of the student you want to insert:"); scanf ("% s", & s-> addr); s-> next = L-> next; L-> next = s } / / A pair of linked lists perform node deletion operations void ListDelete (STU* L, char n []) {STU* p = L-> next, * pre = L; / / define the point of p pointer to the header node, define pre pointing to the header node, and pre always point to p's precursor node if (p = NULL) printf ("data is empty and cannot be deleted!") ; else {while (strcmp (p-> name, n)! = 0) {pre = p; p = pre- > next; if (p = = NULL) {printf ("No relevant information was found and cannot be deleted\ n"); return }} pre- > next = p-> next; free (p); printf ("deleted successfully");}} void LIstSearch (STU* L, char n []) {STU* p = L-> next; if (p = = NULL) printf ("data is empty and cannot be found!") ; else {while (strcmp (p-> name, n)! = 0) {p = p-> next; if (p = = NULL) {printf ("No relevant information found\ n"); return;}} printf ("the student's place of origin is:\ n") Printf ("\ t% s\ n", p-> jg);}} void ListModify (STU* L, char na []) {char JG [60]; STU* p = L-> next; while (p! = NULL) {if (strcmp (p-> name, na) = = 0) {printf ("Please choose your modified place of origin:\ n") Scanf ("% s", & JG); strcpy (p-> jg, JG); break;} p = p-> next;}} void input (STU* p, int I) {printf ("Please enter the student number of% d:", I + 1); scanf ("% s", & p-> no) Printf ("Please enter the name of the% d student:", I + 1); scanf ("% s", & p-> name); printf ("Please enter the phone number of the% d student:", I + 1); scanf ("% s", & p-> tele); printf ("Please enter the ID number of the% d student:", I + 1); scanf ("% s", & p-> D) Printf ("Please enter the place of origin of the% d student:", I + 1); scanf ("% s", & p-> jg); printf ("Please enter the mailing address of the% d student:", I + 1); scanf ("% s", & p-> addr);} void output (STU* L) {STU* p = L-> next While (p! = NULL) {printf ("% s\ t", p-> no); printf ("% s\ t", p-> name); printf ("\ t% s", p-> tele); printf ("\ t% s", p-> D); printf ("\ t% s", p-> jg); printf ("\ t% s", p-> addr) Printf ("\ n"); p = p-> next;}} void PrintFile (STU* L) {STU* p = L-> next; FILE* fp; fp = fopen ("student.txt", "w"); fprintf (fp, "student ID number\ t\ t name\ t\ t ID card number\ t\ t place of origin\ t\ t correspondence address\ n") While (p! = NULL) {fprintf (fp, "% s\ t", p-> no); fprintf (fp, "% s\ t", p-> name); fprintf (fp, "\ t% s", p-> tele); fprintf (fp, "\ t% s", p-> D); fprintf (fp, "\ t% s", p-> jg) Fprintf (fp, "\ t\ t% s", p-> addr); fprintf (fp, "\ n"); p = p-> next;} printf ("saved successfully, please check in the student.txt file in the current directory"); fclose (fp);} void menu () {printf ("\ n\ n"); printf ("\ t\ t\ t = academic examination registration management system =\ n") Printf ("\ t\ t\ t * author: XXX class: XXXXXXXX student number: XXXXXXXXXXXXXXX *\ n"); printf ("\ t\ t\ t *\ n"); printf ("\ t\ t\ t * 1 >. Enter the relevant information of the students *\ n "); printf ("\ t\ t\ t * 2 >. Relevant information about all students *\ n "); printf ("\ t\ t\ t * 3 >. Find a student's place of origin *\ n "); printf ("\ t\ t\ t * 4 >. Modify a student's place of origin *\ n "); printf ("\ t\ t\ t * 5 >. Delete information about a student *\ n "); printf ("\ t\ t\ t * 6 >. Insert information about a student *\ n "); printf ("\ t\ t\ t * 7 >. Save student information *\ n "); printf ("\ t\ t\ t * 0 >. Exit the management system *\ n "); printf ("\ t\ t* Welcome to use this system! *\ n "); printf ("\ t\ tkeeper =\ n "); printf ("\ t\ t enter options, press enter options:\ n ") } int main () {int item, n; / item to receive the input command, n to receive the number of students char nam [30]; STU* L = NULL; L = LIstInit (L); do {menu (); printf ("Please enter the appropriate number and do the appropriate operation:\ n"); scanf ("% d", & item) Switch (item) {case 1: printf ("Please enter the number of students you want to enroll:"); scanf ("% d", & n); L = ListCreate (L, n); break; case 2: printf ("all student information is as follows:\ n") Printf ("student number\ t\ t name\ t\ t telephone number\ t\ t ID card number\ t\ t place of origin\ t\ t mailing address\ n"); output (L); break; case 3: printf ("Please enter the name of the student you are looking for:"); scanf ("% s", nam) LIstSearch (L, nam); break; case 4: printf ("Please enter the student name you want to modify:"); scanf ("% s", nam); ListModify (L, nam); break; case 5: printf ("Please enter the name of the student you want to delete:") Scanf (% s', nam); ListDelete (L, nam); break; case 6: ListInsert (L); break; case 7: PrintFile (L); break; case 0: printf ("about to quit the student place management system.") Exit (0); default: break;} printf ("\ n\ n");} while (item); return 0;}
Screenshots of some running results
Thank you for your reading, the above is the content of "how to use linked list in C language to realize student place management system". After the study of this article, I believe you have a deeper understanding of how to use linked list to achieve student place management system in C language, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.