In practical problems, a set of data often has different data types. For example, in the student registration form, the name should be a character type; the student number can be integer or a character; the age should be integer; gender should be a character type; the score can be integer or real. It is obvious that this group of data cannot be stored in an array. Because the type and length of each element in the array must be consistent to compile the system processing. In order to solve this problem, another construction data type - "Structure" is given in the C language. It is equivalent to records in other advanced languages.
"Structure" is a type of constructor, which is composed of several "members". Each member can be a basic data type or another constructive type. The structure is both a "constructed" data type, then defined it before explaining and use, that is, construct it. The function is defined before the function is explained and called the function.
Structure definition
Define a general form of a structure:
Struct structure name {member table column};
Members are composed of several members, each member is an integral part of the structure. For each member, it must also be described in the form of:
Type indicator member name;
The name of the member name should meet the writing of the identifier. E.g:
Struct stu {int Num; char name [20]; char sex; float score;
In this structure definition, the structure is called STU, which consists of four members. The first member is NUM, integer variable; the second member is Name, the character array; the third member is SEX, the character variable; the fourth member is Score, real variable. It should be noted that the semicolon after parentheses is indispensable. After the structure is defined, the variable will be performed. Any variable indicating that the structure STU is composed of the above four members. It can be seen that the structure is a complex data type, which is a collection of number of ordered variables that are fixed and type different.
Description of structural type variables
The structural variable has the following three methods. The STU defined above is an example.
1. First define the structure and then explain the structural variable. Such as:
Struct stu {int Num; char name [20]; char sex; float score;}; structure stu boy1, boy2;
The two variables BOY1 and BOY2 are STU structural types. It is also possible to define a symbol constant to represent a structural type, for example:
#define stu struct stustu {int Num; char name [20]; char sex; float score;}; stu boy1, boy2;
2. Describe the structural variables while defining structural types. E.g:
Struct stu {int Num; char name [20]; char sex; float score;} BOY1, BOY2;
3. Directly explain the structural variables. E.g:
Struct {int Num; char name [20]; char sex; float score;} BOY1, BOY2;
The third method and the second method are different in the third method, and the structural variable is directly given. When the BOY1, the BOY2 variable is the STU type, you can assign a value to each member of the two variables. In the above STU structure definition, all members are basic data types or array types. Members can also be a structure that constitutes a nested structure. E.g:
Struct Date {int month;} struct {int num; char name [20]; char sex; struct date birthday; float score;} BOY1, BOY2;
First, a structure DATE is defined, consists of three members of Month, Day (Japan), Year (year). When the variable BOY1 and BOY2 are defined, the members BIRTHDAY are illustrated as the DATA structure type. Member names can be interfered with each other in the same name in other variables. The representation of structural variable members often use structural variables in the program, often use it as a whole. In addition to allowing the same type of structural variables to be assigned to each other, including assignment, input, output, calculation, etc., including assignment, input, output, calculation, etc. in addition to the same type of structural variables, including assignment, input, output, calculation, etc.
The general form of the structural variable member is: structural variable name. Member name, such as: boy1.num, the first person's school number BOY2.SEX, the second person's gender, if the member itself is a structure, the minimum must be found step by step Level members can be used. For example: Boy1.birdHday.month, the first month of the first person can be used separately in the program, identical to ordinary variables. Structural variable assignment
As mentioned earlier, the assignment of structural variables is assigned to each member. The input statement or assignment statement can be used.
[Example 7.1] assigns the structural variable and outputs its value.
Main () {struct stu {int Num; char * name; char sex; float score;} BOY1, BOY2; BOY1.NUM = 102; BOY1.NAME = "zhang ping"; printf ("Input Sex and score / n" ); Scanf ("% c% f", & boy1.sex, & boy1.score; boy2 = boy1; printf ("number =% d / nname =% s / n", boy2.num, boy2.name; printf ("SEX =% C / NSCORE =% f / n", boy2.sex, boy2.score;} struct stu {int num; char * name; char sex; float score;} BOY1, BOY2; BOY1.NUM = 102; BOY1.NAME = "zhang ping"; Printf ("Input Sex and Score / N"); Scanf ("% C% F", & Boy1.sex, & boy1.score); BOY2 = BOY1; Printf ("Number = % D / nName =% S / N ", BOY2.NUM, BOY2.NAME); Printf (" SEX =% C / NSCORE =% f / n ", boy2.sex, boy2.score;
In this program, use the assignment statement to NUM and NAME two members, and Name is a string pointer variable. Dynamically entered the SEX and Score member values with the Scanf function, and then give BOY2 all members of BOY1. Finally, each member value of BOY2 is output separately. This example shows the assignment, input, and output of structural variables.
Initialization of structural variables
If the structural variable is a global variable or a static variable, it can be initialized to assign values. Initialization assignment cannot be initialized for local or automatic structural variables.
[Example 7.2] External structural variable initialization.
Struct stu / * Define structure * / {int Num; char * name; char sex; float score;} BOY2, BOY1 = {102, "zhang ping", 'm', 78.5}; main () {BOY2 = BOY1; Printf ("Number =% D / NNAME =% S / N", Boy2.Num, Boy2.Name); Printf ("SEX =% C / NSCORE =% F / N", Boy2.SEX, Boy2.score; } struct stu {int Num; char * name; char sex; float score;} BOY2, BOY1 = {102, "zhang ping", 'm', 78.5}; main () {boy2 = BOY1; ......} This example In the middle, BOY2, BOY1 is defined as an external structural variable and the BOY1 is initialized. In the main function, the value of BOY1 is given to BOY2, and then output the value of BOY2 members with two PrintF statements.
[Example 7.3] Static structural variable initialization.
Main () {static struct stu / * Defines static structural variables * / {INT NUM; char * name; char sex; float score;} BOY2, BOY1 = {102, "zhang ping", 'm', 78.5}; boy2 = BOY1; Printf ("Number =% D / NNAME =% S / N", Boy2.Num, Boy2.Name); Printf ("SEX =% C / NSCORE =% F / N", Boy2.sex, BOY2. STATIC STRUCT STU {Int Num; char * name; char sex; float score;} BOY2, BOY1 = {102, "zhang ping", 'm', 78.5};
This example is a structural variable that defines the BOY1 and BOY2 as static localization, which can also be assigned to the initialization. Structure array
The elements of the array can also be structural types. It can therefore constitute a structural array. Each element of the structural array is a substructure variable having the same structural type. In practical applications, a population having the same data structure is often used in actual applications. Such as a class of student files, a wage watch of a workshop employee.
The definition method of the structural array is similar to the structural variable, simply indicates that it is an array type. E.g:
Struct stu {int Num; char sex; float score;} boy [5];
Define a structure of the architecture BOY1, a total of 5 elements, Boy [0] ~ Boy [4]. Each array element has a structural form of the Struct STU. An array of external structures or static structures can be initialized, for example:
Struct stu {int num; char sex; float score;} boy [5] = {101, "li ping", "m", 45}, {102, "zhang ping", "m", 62.5}, {103, "HE fang", "f", 92.5}, {104, "Cheng Ling", "F", 87}, {105, "Wang Ming", "M", 58};
When the total element is initialized, the array length may not be given.
[Example 7.4] Calculate the average number of students and the number of people who do not have a profit.
Struct stu {int num; char sex; float score;} boy [5] = {101, "li ping", 'm', 45}, {102, "zhang ping", 'm', 62.5}, {103, "HE fang", 'f', 92.5}, {104, "Cheng Ling", 'F', 87}, {105, "Wang Ming", 'M', 58},}; Main () {Int i, c = 0; float ave, s = 0; for (i = 0; i <5; i ) {s = boy [i] .score; if (Boy [i] .score <60 ) C = 1;} Printf ("s =% f / n", s); AVE = S / 5; Printf ("Average =% f / ncount =% D / N", AVE, C);} This example A total of 5 elements in the program are defined in the program, and the initialization assignment is initialized. In the main function, use the for statement to accumulate the SCORE member value of each element in S, such as the value of the score is less than 60 (not grid), that is, the counter C plus 1, the cycle is completed, calculate the average score, and output the total class total points , The average division does not have the number of people.
[Example 7.5] Establishing a classmate address book
#include "stdio.h" #define num 3struct mem {char name [20]; char phone [10];}; main () {struct mem man [num]; int i; for (i = 0; i A structural MEM is defined in this program, which has two members name and phone to indicate names and phone numbers. Define MANs as an array of structures having a MEM type in the main function. In the FOR statement, use the Gets function to enter the value of two members in each element. Then use the PrintF statement in the for statement to output two member values in each element. Structural pointer variable Description of the structural pointer variable and use a pointer variable When used to point to a structural variable, it is called a structural pointer variable. The value in the structural pointer variable is the first address of the structural variable pointed to. This structural variable can be accessed by the structural pointer, which is the same as the case of the array pointer and the function pointer. The general form of structural pointer variable description is: Struct structure name * structural pointer variable name For example, the structure of the STU is defined in the previous example 7.1, and if a pointer variable PSTu pointing to the STU is written as: Struct stu * pstu; Of course, the PSTU can be specifically described when defining the STU structure. As in the previous type of pointer variables as discussed above, the structural pointer variable must also be assigned before it can be used. Assignment is the first address of the structural variable to the pointer variable and cannot give the structure name to the pointer variable. If BOY is a structural variable that is illustrated as a STU type, then PSTU = & BOY is correct, and: PSTU = & stu is wrong. Structural names and structural variables are two different concepts and cannot be confused. The structural name can only represent a structure, and the compilation system does not assign memory space to it. The storage space is allocated only when a variable is illustrated as this type of structure. Therefore, the above & stu is wrong, it is impossible to take a structural name of the first address. With a structural pointer variable, you can easily access the various members of the structural variable. The general form of its access is: (* structural pointer variable). Member name or is: Structural pointer variable -> member name For example: (* PSTU) .Num or: pstu-> num It should be noted that the brackets on both sides are not less, because the membership "." The priority is higher than "*". If you go to the bracket writing * pstu.num is equivalent to * (pstu.num), so that the meaning is completely wrong. The specific description and method of use of structural pointer variables will be described below. [Example 6] Struct stu {int Num; char sex; float score;} boy1 = {102, "zhang ping", 'm', 78.5}, * pstu; main () {PSTU = & boy1; printf ("Number = % d / nName =% s / n ", boy1.num, boy1.name); Printf (" SEX =% C / NSCORE =% f / n / n ", boy1.sex, boy1.score; printf (" Number =% d / nname =% S / N ", (* PSTU) .Num, (* PSTU) .Name); Printf (" SEX =% C / NSCORE =% f / n / n ", (* PSTU) .SEX, (* PSTU) .score; Printf ("Number =% D / NNAME =% S / N", PSTU-> Num, PSTU-> Name); Printf ("SEX =% C / NSCORE =% F / N / N ", PSTU-> SEX, PSTU-> score; This example defines a structural STU that defines the STU type structure variable BOY1 and performs initialization assignment, and a pointer variable PSTU that points to the STU type structure is also defined. In the main function, the PSTU is given the address of BOY1, so the PSTU points to BOY1. Then output all members of BOY1 in three forms in the printf statement. As can be seen from the results: Structural variables. Member name (* Structural pointer variable). Member name Structural pointer variable -> member name These three forms used to represent structural members are completely equivalent. The structural array pointer variable structural pointer variable can point to an array of structures, and the value of the structural pointer variable is the first address of the entire structure array. The structural pointer variable can also point to an element of the structural array, and the value of the structural pointer variable is the first address of the array element of the structure. Set PS to point to the pointer variable of the structure array, the PS also points to the No. 0 element of the array of the structure, PS 1 points to the 1st element, PS i points to the I number. This is consistent with the case of a normal array. [Example 7.7] An array of structural arrays is output with a pointer variable. Struct Stu {Int Num; Char * Name; Char Sex; Float Score;} Boy [5] = {101, "Zhou Ping", 'M', 45}, {102, "ZHANG Ping", 'M, 62.5}, {103, "liou fang", 'f', 92.5}, {104, "Cheng Ling", 'F', 87}, {105, "Wang Ming", 'M, 58},}; Main () {struct stu * ps; printf ("no / tName / T / T / T / TSEX / TSCORE / T / N"); for (PS = Boy; PS PS = & boy [1] .sex; but only: ps = boy; (given the first address) or it could be: PS = & boy [0]; (giving the first address of the No. 0 element) Structure pointer variable function parameters The structure variable function parameters are allowed in the ANSI C standard. But this transmission is to transmit all members one by one, especially when members are array, which will make the time and space overhead of the transfer, and severely reduce the efficiency of the program. Therefore, the best way is to use pointers, ie, with pointer variables, function parameters. At this time, it is only the address of the first parameter to the address, thereby reducing the cost of time and space. [Example 7.8] The topic is the same as that of Example 7.4, calculating a number of students average scores and number of people. Structure pointer variables to program function parameters. Struct stu {int num; char sex; float score;} boy [5] = {101, "li ping", 'm', 45}, {102, "zhang ping", 'm', 62.5}, {103, "HE fang", 'f', 92.5}, {104, "Cheng Ling", 'F', 87}, {105, "Wang Ming", 'M', 58},}; Main () {struct stu * ps; void AVE (STRUCT STU * PS); PS = Boy; AVE (PS);} Void AVE (Struct Stu * PS) {INT C = 0, I; Float Ave, S = 0 For (i = 0; i <5; i , ps ) {s = ps-> score; if (ps-> score <60) C = 1;} Printf ("s =% f / n", s) AVE = S / 5; Printf ("Average =% f / ncount =% D / N", AVE, C);} The function AVE is defined in this program, and its shape is reflected in the structural pointer variable PS. BOY is defined as an external structure array, so it is valid throughout the program. In the main function, the structural pointer variable PS is defined, and the first address of the BOY is given to the PS point to the BOY array. Then use the PS to do the reference function AVE. Complete the calculation average score and statistics in the function AVE and output the result. Compared with the example 7.4, since the programs are all used by the pointer variables, the speed is faster and the program efficiency is higher. .topoic = dynamic storage allocation In an array chapter, it has been introduced that the length of the array is predefined, and it is fixed throughout the program. Dynamic array types are not allowed in C language. For example: int N; scanf ("% d", & n); int a [n]; uses variables to represent the length, want to dynamically explain the size of the array, which is wrong. But in actual programming, this often occurs, ie the required memory space depends on the actual input data, and cannot be predetermined. For this problem, it is difficult to solve with an array approach. In order to solve the above problems, the C language provides some memory management functions, which can be dynamically allocated to memory space as needed, or the space that is no longer used, which provides means for efficiently utilizing memory resources. Common memory management functions have the following: 1. Allocate memory space function Malloc Call Form: (Type Desifter *) Malloc (size) Function: Allocated a continuous area of a length of "size" byte in the memory area. The return value of the function is the first address of the area. "Type Desorph" indicates what data types are used to use this area. (Type Design *) Indicates that the return value is forced to convert to the type pointer. "Size" is an unsigned number. For example: PC = (char *) malloc (100); indicates that the memory space allocated, forced to convert to the character array type, the return value of the function is a pointer to the array of characters, and imparts the pointer variable PC . 2. Allocate memory space function Calloc Calloc is also used to allocate memory space. Call Form: (Type Design *) Calloc (n, size) Function: Allocated the continuous area of the N block length "size" byte in the memory dynamic storage area. The return value of the function is the first address of the area. (Type Design *) is used for mandatory type conversion. The difference between the Calloc function and the Malloc function is only to allocate an N block area at a time. For example: ps = (struet stu *) Calloc (2, sizeof (struct stu)); SizeOf (Struct Stu) is a structural length of the STU. Therefore, the statement means that the 2-piece continuous zone is assigned according to the length of the STU, and forced to convert to the STU type, and the first address is given to the pointer variable PS. 3. Release the memory space function free Call form: free (void * ptr); Function: Release a plurality of memory space points to PTR, PTR is an arbitrary type pointer variable, which pointing to the first address of the released area. The released area should be area assigned by the Malloc or Calloc function: [Example 7.9] Assign a zone to enter a student data. Main () {struct stu {int Num; char * name; char sex; float score;} * ps; ps = (struct stu *) malloc (Struct Stu); ps-> num = 102; ps-> Name = "zhang ping"; ps-> sex = 'm'; ps-> score = 62.5; printf ("number =% d / nname =% S / N", PS-> Num, PS-> Name); Printf ("SEX =% C / NSCORE =% F / N", PS-> SEX, PS-> Score; Free (PS);} In this case, the structure STU is defined to define the STU type pointer variable PS. Then allocate a STU large memory area and assign the first address to the PS to point to the area. Then, the PS is assigned to the pointer variables to each member, and each member value is output with the PrintF. Finally, use the Free function to release the memory space points to the PS. The entire program contains three steps of application for memory space, using memory space, and releases in memory space to realize dynamic allocation of storage space. The concept of the list is a dynamic allocation method in Example 7.9 to allocate memory space for a structure. Each time a piece of space can be used to store a student's data, we can call it a node. How many students should apply for how many memory spaces are applied, that is, how many nodes should be established. Of course, the above work can also be done with the structural arrays, but if you can't accurately grasp the number of students in advance, you will not be able to determine the array size. And when the student is resumed, the space occupied by the element cannot be released from the array. These issues can be solved well with dynamic storage. There is a student to allocate a node, there is no need to predetermine the accuracy of the students, a student's dropout, can delete the node, and release the storage space occupied by this node. Thereby saving valuable memory resources. On the other hand, the method of using an array must take up a continuous memory area. When dynamic allocation, each node can be discontinuous (continuous in the node). The connection between nodes can be implemented with a pointer. That is, a member item is defined in the node structure to store the first address of the next node, which is used to store the address of the address, often referred to as a pointer domain. The first address of the second node can be stored in the first node's pointer domain, and the first address of the third node is stored in the pointer domain of the second node, so that the last node is connected. . The last node is connected due to the subsequent junction, and its pointer domain can be 0. Such a connection method is referred to in the data structure as "linked list". In the linked list, the 0th junction is called the head knot, which stores the first address of the first node, which has no data, just a pointer variable. Each of the following nodes is divided into two domains, one is a data domain, stores various actual data, such as student Num, Name Name, Gender SEX, and grades SCORE. Another domain is a pointer domain, and the first address of the next node is stored. Each node in the linked list is the same structural type. For example, a node that stores student scholars and grades should be the following structure: Struct Stu {Int Num; int score; struct stu * next;} The first two members constitute a data field, and the last member NEXT constitutes a pointer domain, which is a pointer variable to the STU type structure. The basic operation of the linked list has the following main operations of the linked list: 1. Establish a linked list; 2. Structure search and output; 3. Insert a node; 4. Delete a node; These operations are explained below by example. [Example 7.10] Establish a three node linked list to store students' data. For the sake of simplicity, we assume that only two student data structures are only two people and age. You can write a function Creat created to create a list. The procedure is as follows: #define null 0 # Define Type Struct Stu # Define Len SizeOf (Struct Stu) Struct Stu {Int Num; Int Age; Struct Stu * Next;}; type * creat (int N) {struct stu * head, * pf, * Pb; Int i; for (i = 0; i The three symbol constants are defined by macro definitions in the function. Here, use Type, Struct Stu, using LEN to indicate the main purpose of SizeOf (Struct Stu) to reduce writing and make reading more convenient in the following procedure. The Structure STU is defined as an external type, and each function in the program can use this definition. The CREAT function is used to create a linked list with n-nodes, which is a pointer function, which is the pointer to the STU structure. The pointer variables of three STU structures are defined in the CREAT function. Head is the head pointer, PF is a pointer variable that pointing the front node of two adjacent points. Pb is the pointer variable of the latter node. In the For statement, the space with the Malloc function is established to equal the length equal to the STU as a node, and the first address gives PB. Then enter the node data. If the current node is the first node (i == 0), the Pb value (this node pointer) is given to the HEAD and PF. If a non-first node, the PB value is given the node member NEXT of the node of the PF. The pointer of PB is the current last node, which refers to the needle domain NULL. The PB value is given to PF to prepare a cycle. The shape of the CREAT function represents the number of nodes of the built-in table, as the number of cycles of the for statement. Figure 7.4 represents the execution process of the CREAT function. [Example 7.11] Write a function and find this node in the linked list. TYPE * Search (Type * Head, INT N) {TYPE * P; INT i; p = head; while (p-> num! = N && p-> next! = Null) P = P-> next; / * Not the node to find, move one step * / if (p-> Num == n) Return (P); if (p-> num! = N && p-> next == null) Printf ("Node% D HAS NOT BEEN FOUND! / N ", N} The symbol constant Type used in this function is the same as the macro of the Example 7.10, equal to the Struct STU. There are two ginseng, and the head is a pointer variable to the linked list, and n is the school number to find. Enter the While statement, check if the NUM member of the node is equal to N. If it is not equal to N and the pointer domain is not equal to NULL (not the last node), then moves a node, continue to loop. If this node is found, the node pointer is returned. If the end of the cycle does not find the node, the "Not found" prompt information is output. [Example 7.12] Write a function and delete the specified node in the list. There are two situations that delete a node: 1. The deleted node is the first node. This situation only needs to point the HEAD to the second node. Head = pb-> next. The process is shown in Figure 7.5. 2. The deleted point is not the first node. This situation can point the front spoint of the deleted point points to the rear node of the deleted point. PF-> Next = Pb-> Next. The function programming is as follows: TYPE * delete (type * head, int num) {type * pf, * pb; if (head == null) / * such as empty table, output prompt information * / {printf ("/ nempty list! / N") Goto end;} PB = head; while (pb-> Num! = NUM && PB-> Next! = Null) / * When not the node to delete, it is not the last node, continue to loop * / {PF = Pb; PB = PB-> Next;} / * pf points to the current node, PB points down the next node * / if (Pb-> Num == Num) {if (Pb == Head) Head = Pb -> next; / * If you find the deleted node, and the first node, make the head point to the second node, otherwise the pointer to the node of the PF points to the next junction * / else Pf-> Next = PB-> Next; Free (PB); Printf ("The Node Is Delected / N");} else printf ("The node not been foud! / n"); end: return head;} There are two ginseng, and Head is a pointer variable to the first node of the linked list, and Num deleted the student number. First determine if the linked list is empty, it is impossible to have an adjjopt point. If it is not empty, the PB pointer points to the first node of the list. After entering the While statement, look up one by one. After finding the deleted node, look at whether it is the first node, if it makes the head point to the second node (ie, delete the first node from the chain), otherwise, the front node of the deleted point is made ( PF refers to the rear node (referred to as the pointer domain) of the deleted node). If the end of the loop does not find the node to delete, the prompt information found "is output. Finally returns the HEAD value. [Example 7.13] Write a function and insert a node in the specified location in the list. Insert the node in the specified location of a linked list, requiring the list itself must be in a certain regular sequence. For example, in a student data linked list, you are required to insert a node in order. The pointer to which is tied is PI. Can be inserted in three different situations. 1. Original table is a blanket, just make the head point to the tie point. 2. The slot point value is minimized and should be inserted before the first node. In this case, the Head points to the plot point, the pointer domain of the plug point points to the original first node. which is: Pi-> Next = Pb; Head = Pi; 3. Insert in other locations. In this case, the pointer domain of the front node of the insertion position points points to the tie point, and the pointer domain of the plug point points points to the rear node of the insertion position. That is: pi-> next = pb; pf-> next = pi; 4. Insert in the end of the surface. In this case, the original surface end node pointer domain points to the tie point, and is set to NULL by the interpolation point. which is: PB-> Next = Pi; Pi-> Next = NULL; TYPE * INSERT (TYPE * HEAD, TYPE * PI) {TYPE * PF, * PB; PB = HEAD; if (Head == Null) / * Empty table Insert * / (Head = pi; pi-> next = null;} else {while ((pi-> num> pb-> num) && (pb-> next! = Null) {pf = Pb; PB = PB- > Next;} / * find insertion position * / if (pi-> num <= pb-> num) {if (head == pb) Head = Pi; / * Insert * / else PF before the first node > Next = Pi; / * Insert * / pi-> next = Pb in other locations;} else {PB-> Next = Pi; pi-> next = null;} / * Insert * /} return head; } This function has two shape parameters for pointer variables, and Head points to the linked list, PI points to be interposed. The function is first determined whether the linked list is empty, which makes the Head point to the plot point. Table, if not, then Use the While statement loop to find the insertion position. After finding it, it is determined whether or not before inserting before the first node. If the Head point to the tie point points to the original first node, otherwise insert, if The inserted node is greater than all nodes in the table, then insert in the surface. This function returns a pointer to the head pointer of the linked list. When the inserted position is in the first node, the new knot inserted into a linked list. The first node, so the value of Head has changed, so it needs to return this pointer to the main adjustment function. [Example 7.14] Configure the above, delete nodes, and insert a function organization that is inserted, and then built a function that outputs all nodes, and then calls them with the main function. #define null 0 # Define Type Struct Stu # Define Len SizeOf (Struct Stu) Struct Stu {Int Num; Int Age; Struct Stu * Next;}; type * creat (int N) {struct stu * head, * pf, * Pb; Int i; for (i = 0; i Head = delete (head, num); Print (Head); Printf ("INPUT THE INSERTED NUMBER AND AGE:"); PNUM = (Type *) Malloc (LEN); Scanf ("% D% D", & pnum-> Num, & PNUM-> AGE); Head = INSERT (HEAD, PNUM); Print (HEAD);} In this example, the Print function is used to output each node data domain value in the list. The initial value of the function of the function of the function points to the first node of the linked list. In the While statement, after outputting the node value, the HEAD value is changed and pointing down the next junction. If the header pointer header header Head should be left, a pointer variable should be set, which gives it to it, and use it to replace HEAD. In the main function, n is the number of established nodes, NUM is a data domain value to be denied; Head is a head pointer to the linked list, and PNum is a pointer to the tie point. The meaning of each line in the main function is: The sixth line input the number of nodes of the list; The seventh line adjusts the CREAT function to establish a lin list and return the head pointer to Head; The eighth line adjustment print function output linked list; The tenth line enter the students who want to be deleted; The eleventh line adjusts the delete function to delete a node; The twelfth line of print function output linked list; The fourteenth line adjustment Malloc function assigns a node memory space and gives its address to PNUM; The fifteenth line inputs the data domain value to be inserted into the node; The sixteenth line adjustment insert function is inserted into the node referred to in PNUM; Chain Turn again to the Print function output linked list. From the results of the operation, first establish a linked list of 3 nodes, and output its value; delete 103 nuts, only 105, 108 junction; enter the 106 number data, insert into the rear chain table The node is 105, 106, 108. Joint "combination" is also a data structure for constructive types. In a "combination", a variety of different data types can be defined, one of the variables that are described as the "federation" type, allowing any of the data defined by the "United". This is not available in the previous data types. For example, defined a variable that can only be loaded into an integer data, defined as a real value can only be given to real data.