1 # include <stdlib. h> 2 # include <stdio. h> 3 typedef struct node 4 {5 Int data; 6 struct node * Next; 7} node, * linklist; 8 9 void initlist (linklist * l) 10 {11 (* L) = NULL; 12 printf ("initialization successful \ n"); 13} 14 15 linklist creatlist (int n) 16 {17 linklist L, H, s; // L is the tail pointer, H is the head pointer, S is the work pointer 18 int I = 0; 19 if (H = (linklist) malloc (sizeof (node) = NULL) 20 {21 printf ("no space available! "); 22 exit (0); 23} 24 h-> DATA = 0; 25 h-> next = NULL; 26 L = H; 27 for (; I <N; I ++) 28 {29 If (S = (linklist) malloc (sizeof (node) = NULL) 30 {31 printf ("no space can be allocated! "); 32 exit (0); 33} // create a node 34 L-> next = s; // link with the end node 35 printf ("Enter the % d Number", I + 1); 36 scanf ("% d ", & (S-> data); // input data 37 S-> next = NULL; // null 38 L = s; // remove the tail pointer 39 40} 41 return h; 42} 43 44 int main () 45 {46 linklist listlist = NULL; 47 initlist (& listlist ); 48 listlist = creatlist (5); 49 return 0; 50}
During creation, 34-38 rows, links, data input, left blank, tail pointer backward shifting, variable sequence, and post-shifting must be placed behind the link