Summary of a single-chain table without a header ---- dynamically create a linked list and a single-chain table ----
1 # include "head. h "2 struct Student * creat () 3 {4 struct Student * head, * p1, * p2; // open up three struct pointers first, * head, (As the returned header pointer) 5 p1 = p2 = (struct Student *) malloc (LEN); 6 scanf_s ("% s % f", p1-> num, N, & p1-> score); // read the input information first, and Judge 7 head = NULL according to the read information; // first point the header pointer to a NULL pointer 8 n = 0; // count the number of members in the chain table 9 while (strcmp (p1-> num, "0 ")! = 0) // Based on the read information, "0" indicates the input termination label. If not 10 // 0, add 11 {12 ++ n to the linked list; // if it is not terminated, add a member 13 if (n = 1) head = p1; // first assign the starting address to the header pointer, because p1 will be moved back next, 14 // No header pointer information 15 else p2-> next = p1; // p1 is divided into two situations, when n = 1, p1 is assigned to the header pointer. next, p1 links 16 // The previous pointer p2-> next; 17 p2 = p1; // After the link is completed, p2 moves to p1. 18 p1 = (struct Student *) malloc (LEN); // then p1 continues to develop new memory storage members; 19 scanf_s ("% s % f", p1-> num, n, & p1-> score); // reads new member information, returns to the beginning, reads 20 // reads 21} 22 p2-> next = NULL; // It is the next of p2 as the end mark. Note that p1 is used to store the "0" 23 // The 24 return head condition is terminated; // return header pointer 25}