# Include <stdio. h> # include <stdlib. h> typedef struct node {int data; // data field node * Next; // pointer field, pointing to the next node} node; node * Create (); // create a single-chain table int deletefromlist (node * linklist, int I); // If the node is deleted successfully, 0 is returned; otherwise,-1int insertintolist (node * linklist, int I, int value) is returned ); // If the node is successfully inserted, 0 is returned. Otherwise,-1 void display (node * linklist) is returned. // traverse and print the linked table void main () {node * linklist = create (); // display (linklist); insertintolist (linklist, 5, 30); display (Lin Klist); deletefromlist (linklist, 5); display (linklist);} node * Create () {int n = 20; node * plist, * pnew, * ptail; plist = (node *) malloc (sizeof (node); plist-> next = NULL; ptail = plist; // For (INT I = 1; I <= N; I ++) {pnew = (node *) malloc (sizeof (node); If (pnew = NULL) {printf ("error !! "); Exit (0);} pnew-> DATA = I; pnew-> next = NULL; ptail-> next = pnew; ptail = pnew ;} ptail-> next = NULL; return plist;} int insertintolist (node * linklist, int I, int value) {// first find whether the node * P, * q; int J = 1; // count P = linklist; while (P & J <I) // find the I-th node {P = p-> next; + + J;} If (! P | j> I) {return-1; // the I-th node does not exist. insertion Failed} // now P is in the 4th position, p-> next points to the fifth value q = (node *) malloc (sizeof (node); q-> DATA = value; q-> next = p-> next; // mount the fifth value and subsequent linked list to Q-> next pointer p-> next = Q; // link Q and the link above and below to Q-> next to P-> next return 0;} int deletefromlist (node * linklist, int I) {// check whether node * PTR exists on node I; Int J = 1; PTR = linklist; while (PTR-> next & J <I) {PTR = PTR-> next; ++ J;} If (! (PTR-> next) | j> I) {return-1; // node I does not exist} PTR-> next = PTR-> next; return 0;} void display (node * linklist) {While (linklist-> next) {printf ("% d \ n", linklist-> next-> data ); linklist = linklist-> next ;}}