# include & ltstdlib.h & gt
# include & ltstring.h & gt
# Definition Menu _ No.7
# Define N 3
Typedef structure s 1
{
Character number [11]; /* The student number consists of 10 characters */
char name[ 15]; /* Student name */
Floating score [n]; /* Results of various courses */
Floating sum; /* Total score */
Floating average; /* Average score */
Int order; /* Rank */
struct s 1 * next; /* Pointer to subsequent node */
} students; /* Define the structure type */
Student * head = NULL
void input data(STUDENT * ptr);
void print menu();
int Menu _ Select();
void Init();
void create();
Void print ();
void Delete();
void append();
Void computer ();
Master ()
{
Int key;
while( 1) {
key = Menu _ Select();
Switch (key)
{
Case 0: init ();
//Preliminary linked list. That is, if the linked list is not empty, all data in the linked list will be released and the header will be set to NULL.
Break;
Case1:create ();
//Create a linked list and enter data.
Break;
Case 2: delete ();
//Delete the record data of the specified student number.
Break;
Case 3: print ();
//Print all the data in the linked list.
Break;
Case 4: Computer ();
//Calculate the total score and average score of all people in the linked list
Break;
Case 5: Append ();
//Append data to the end of the linked list.
Break;
Case 6: init ();
//Release the linked list
Exit (0);
}
};
}
Void print menu ()
{
int I;
char * menu[]={
"0. Initialization list",
"1. input list",
"2. Delete records from the list",
"3. Print the list",
"4. Calculate the score",
"5. Insert the record into the list",
"6. Quit"
};
printf(" \ n \ n ");
for(I = 0; My < menu _ number; i++)
printf("%s\n ",menu[I]);
Printf ("\ nEnter your choice (0-6):");
}
int Menu_Select()
{
Int key;
print menu();
Scanf("%d ",&key);
Enter key;
}
Void Init() // Initializes a single linked list. That is, release all the data in the linked list.
{
Students *p, * ptr// define two temporary pointer variables p, ptr.
P = head; Ptr = head// Point two temporary variables to the head pointer head;
while(ptr! = empty)
{
ptr = ptr-& gt; Next; //ptr points to the next structure data.
Free (p); //Release the memory of the structure data pointed by p..
P = ptr// Point p to the data pointed by ptr.
}
Head = NULL// Point the head to null.
}
Void create() // Create a linked list.
{
Students *pt, * pth = NULL// define two pointer variables: PT points to the new data memory to be applied and pth points to the current data.
while( 1)
{
Pt= (student *)malloc(sizeof)); //Let pt point to the newly applied memory space.
Input data (pt); //Input data, which is stored in the structure data pointed by pt. Pay attention to let the next pt point to NULL.
if(strcmp(pt-& gt; No, "@" = = 0)
{
Free of charge (PT); //Release the memory space pointed by pt.
Break; //Exit the loop
}
else if (head==NULL)
{
pth = pt
Head = pt// point the head pointers head and pth to pt.
}
other
{
PTH-& gt; Next = pt// Point the next pth to PT;
Pth = pt// Point pth to PT;
}
};
}
Void print() // prints all the data in a single linked list.
{ int I = 0;
Student * p;; //The first pointer p
P = head; //Point P to the head
printf(" \ n ");
Printf ("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n
printf(" | rec | no | name | sc 1 | sc2 | sc3 | sum | ave | order | \ n ");
printf(" |-|-|-|-|-|-|-|-|-|-| \ n ");
//Print the title
And (p! = empty)
{
printf(" | % 3d | % 10s | %- 16s | % 4. 1f | % 4. 1f | % 4. 1f | % 6.2f | % 5. 1f | % 5d | \ n ",
++i,p-& gt; No, P-> Name, p-> Score [0], p-> Score [1], p-> Score [2],
p->; Sum, p- > average, p->; Order); //Print all data in the structure pointed by p ... Pay attention to the dividing line between printed data.
p = p-& gt; Next; //Point p to the next structure data of p..
}
printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * END * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n "); //Print footer
}
Void Delete() // Delete a record.
{
Students *p, * pth// define two pointers p, pth.
Character number [11]; //Define an integer no (used to store the input student number)
Printf ("Enter Delete No \ n");
Scanf("%s ",no); //Enter a student number with the input statement and store it in NO.
P = head; Pth = head; //point both p and pth to the head pointer.
if(strcmp(p-& gt; No, no) ==0) // That is, whether the data pointed by the head pointer needs to be deleted.
{
head = head-& gt; Next; //Point the head pointer to the next data of the head;
Free (p); //Release the data pointed by p..
}
other
{
p = p-& gt; Next; //Point p to the next data of p..
And (p! = empty)
{
if(strcmp(p-& gt; No, no) ==0) // Find the data to delete.
{
PTH-& gt; next = p-& gt; Next; //Point the next pth to the next P.
Free (p); //release p
Break; //Exit the loop
}
other
{
PTH = PTH-& gt; Next; //point pth to the next pth or point pth to p.
p = p-& gt; Next; //point p to the next one of p.
}
}
}
}
Void addition ()
{
Students *p, * pth// define two pointer variables p, pth.
Pth = head; //Point the pointer to the head.
while(PTH-& gt; Au Suivant! = empty)
{
PTH = PTH-& gt; Next; //ptr points to the next ptr.
}
P= (student *)malloc(sizeof)); //Point p to the newly requested memory space.
Input data (p); p->; Next = NULL//data data is stored in the memory space pointed by P. Pay attention to setting the next of P to NULL.
PTH-& gt; next = p; //Point the next ptr to p..
}
Invalid input data (student *ptr)
{ int I;
Printf ("input number:");
scanf("%s ",ptr-& gt; No);
if(strcmp(ptr-& gt; No, "@" = = 0) returns;
Printf ("Enter name:");
scanf("%s ",ptr-& gt; Name);
for(I = 0; I<3; i++)
{
Printf ("Shu Ru Ji Cheng \ n");
scanf("%f ",& ampptr-& gt; score[I]);
}
ptr-& gt; sum = 0;
ptr-& gt; Average value = 0;
ptr-& gt; Order = 0;
ptr-& gt; next = NULL
}
Invalid computer ()
{
Student * p;;
P = head;
for(; p; p = p-& gt; Next)
{
p->; sum = p-& gt; Score [0]+p-> Score [1]+p-> Score [2];
p->; Average value = (p-> Score [0]+p-> Score [1]+p-> Score [2])/3;
}
}