# Include <stdio. h> # define type struct Stu # define Len sizeof (struct Stu) struct Stu {int num; int age; struct Stu * Next;}; type * creatlink (int n ); type * deletelink (type * head, int num); Type * insertlink (type * head, type * PI); void printlink (type * head ); void destroylink (type * head); void main (void) {type * head = NULL, * pnum = NULL; int n = 3, num; /* Create a linked list containing N nodes */printf ("input number of node:"); Head = Creatlink (n); printlink (head);/* Delete the node with the value of num in the linked list */printf ("input the deleted number:"); scanf ("% d ", & num); Head = deletelink (Head, num); printlink (head);/* Insert a node into the linked list */printf ("insert a record \ n "); pnum = (type *) malloc (LEN); If (pnum = NULL) printf ("pointer is null -- Memory alloc fail! "); Printf (" input the inserted number: "); scanf (" % d ", & pnum-> num); printf (" input the inserted age :"); scanf ("% d", & pnum-> age); Head = insertlink (Head, pnum); printlink (head);/* destroy the linked list, release dynamically allocated memory */destroylink (head);}/* Create a linked list containing N nodes */type * creatlink (int n) {type * head = NULL, * PF, * pb; int I; for (I = 0; I <n; I ++) {Pb = (type *) malloc (LEN ); printf ("record % d \ n", I); printf ("input number:"); scanf ("% d", & Pb-> Num); printf ("input age:"); scanf ("% d", & Pb-> age); if (I = 0) pF = head = Pb; else PF-> next = Pb; Pb-> next = NULL; pF = Pb;} return (head );} /* Delete the node with the value of num in the linked list */type * deletelink (type * head, int num) {type * PF, * pb; If (Head = NULL) {printf ("\ nempty list! \ N "); return NULL;} Pb = head; while (Pb-> num! = Num & Pb-> next! = NULL) {pF = Pb; Pb = Pb-> next;} If (Pb-> num = num) {If (PB = head) head = Pb-> next; else PF-> next = Pb-> next; free (PB); printf ("the node is deleted \ n ");} else printf ("the node not been found! \ N "); return head;}/* Insert a node in the linked list */type * insertlink (type * head, type * PI) {type * pb, * PF; PB = head; If (Head = NULL) {head = PI; Pi-> next = NULL;} else {While (Pi-> num> Pb-> num) & (Pb-> next! = NULL) {pF = Pb; Pb = Pb-> next;} If (Pi-> num <= Pb-> num) {If (Head = Pb) head = PI; else PF-> next = PI; Pi-> next = Pb;} else {Pb-> next = PI; Pi-> next = NULL ;}} return head;}/* print the node information in the linked list */void printlink (type * head) {printf ("number \ t \ Tage \ n"); While (Head! = NULL) {printf ("% d \ t % d \ n", head-> num, head-> age); Head = head-> next ;}} /* destroy the linked list and release the dynamically allocated memory */void destroylink (type * head) {type * P, * q; P = head; while (P! = NULL) {q = p-> next; free (p); P = Q ;}}