The entry and query of the student management system score with the linked list is already realized

Source: Internet
Author: User

#define _crt_secure_no_warnings#include <stdio.h> #include <stdlib.h> #include <string.h>typedef struct Teacher{char name[32];int math;int english;int data;struct Node *next;} Slist;int creat_slist (); int slist_print (); int slist_selectprint (SLIST *phead); int creat_slist (SLIST **handle) {Char NAME[32] = {0};int flag = 0;int Math = 0;int 中文版 = 0;int ret = 0; SLIST *phead = null, *pcur = null, *PM = null;//First allocates memory Phead = (SLIST *) malloc (sizeof (SLIST)); if (phead = = null) {ret = -1;PR Intf ("Func creat_slist err ret=%d", ret); return ret;} Phead->data = 0;phead->next = null;//Here makes the current node equal to the head node Pcur = phead;while (Flag! =-1) {PM = (SLIST *) malloc (sizeof (SLIST)) ; if (PM = = NULL) {//slist_destory (phead); ret = -2;printf ("func creat_slist () err:%d malloc err", ret); return ret;} Char name[32] = {0};p rintf ("Enter student's name"), scanf ("%s", name), strcpy (pm->name, name);//pm->name[] = name;printf ("please Enter the student's math Score "); scanf ("%d ", &math);p M->math = math;printf (" Please enter student English scores "); scanf ("%d ", &english);p m->english = english;printf ("Assuming that the current student's edits are entered-1 enter 1 \ n" To continue entering student information); SCANF ("%d", &flag);p M->next = NULL ;//Let PM connect to the back of the pcur is a description of the phead is not stored data but an empty head node Pcur->next = Pm;pcur = PM;} *handle = Phead;return ret;//end:}int slist_print (SList *phead) {int ret = 0; SLIST *p = Null;p = Phead->next;//bugif (Phead = = NULL) {return-1;} printf ("\nbegin");//p = P->next;while (p) {//printf ("%d\n", P->data);p rintf ("Student's name");p rintf ("%s\n", P->name ;p rintf ("Student math");p rintf ("%d\n", P->math);p rintf ("Student English score");p rintf ("%d\n", p->english);p = P->next;system ("pause"); printf ("End"); return ret;} Outputs an int slist_selectprint (SList *phead) {int ret = 0 to the query; SLIST *p = Null;p = phead;if (Phead = = NULL) {return-1;} printf ("\nbegin"); {printf ("The Student information you are looking for such as");p rintf ("Students ' name");p rintf ("%s\n", P->name);p rintf ("Student Math Score");p rintf ("%d\n", P->math); printf ("Student English scores");p rintf ("%d\n", P->english);} printf ("End"); return ret;} Search for student information need to print find results int slist_select (SList *phead,char *name) {int RET = 0;int flag = 0;char Myname[32] = {0}; SLIST *pcur;strcpy (myname, name), if (Phead = = NULL) {int ret = -1;printf ("Slist_insert err"); return ret;} Pcur = Phead->next;pcur = Phead->next;while (pcur) {//name The first person is able to perform a normal query but not the normal output if (strcmp (Pcur->name, my name) = = 0) {//inferred here is the correct//slist_print (pcur); Slist_selectprint (pcur); flag = 1;break;} Pcur = Pcur->next;} if (flag = = 0) {printf ("No person checked without this person to check without this person");} return ret;} Insert Yint Slist_nodeinsert (SList *phead, int x, int y) where x appears, int slist_nodeinsert (SList *phead, int x, int y) {int ret = 0; SLIST *ppre, *pcur, *pm;if (Phead = NULL) {int ret = -1;printf ("Slist_insert err"); return ret;} Ppre = Phead;pcur = phead->next;//constant malloc new node data field assignment PM = (SLIST *) malloc (sizeof (SLIST));p m->data = Y;pm->next = N Ull;while (pcur) {if (Pcur->data = = x) {break;} Ppre = Pcur;pcur = Pcur->next;} if (PM = = NULL) {ret = -2;printf ("Slist_insert err"); return ret;}  Pm->next = Pcur;//ppre->next;ppre->next = Pm;//ppre = PM; return ret;} Delete FindY and delete it int slist_nodedel (SList *phead, int y) {int ret = 0; SLIST *ppre, *pcur;if (phead = = NULL) {int ret = -1;printf ("Slist_insert err"); return ret;} Ppre = Phead;pcur = Phead->next;while (pcur) {if (Pcur->data = = y) {break;} Ppre = Pcur;pcur = Pcur->next;} if (pcur = = NULL) {printf ("node y:%d not found", y); return-2;} Ppre->next = Pcur->next;//ptemp = Ppre->next;//ppre = Ptemp;return ret;} void Main () {SLIST * Phead = null;int flag = 0;printf ("------------------------Student management system-------------------------\ n"); for ( ;;) {printf ("If you want to enter student information please enter: 1 \ n");p rintf ("If you want to query student information please enter: 2 \ n");p rintf ("If you want to query all students Please enter: 3 \ n"); scanf ("%d", &flag); IF (FLA G = = 1) {creat_slist (&phead);} if (flag = = 2) {printf ("Please enter the name of the person to be queried"), char name[32] = {0};scanf ("%s", name);p rintf ("s%", name);//query and print results Slist_select (Phead,name);} if (flag = = 3) {slist_print (phead);} printf ("----------------------------------------------------------"); System ("Pause");} printf ("\ n");//slist_select (Phead, "Han");//system ("Pause");}

The entry and query of the student management system score with the linked list is already realized

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.