#include <Stdio.H>#include <Stdlib.H>typedef structList{int val; structList *Next;}List;voidInitlist (List **HList **T) {*H=(List *) malloc (sizeof (List));//*h is the address of the head pointer. *T=(List *) malloc (sizeof (List));//*t is the address of the tail pointer. if(!(*H|| !(*T)) exit (-1); (*H -Next= *T (*T -Next= NULL; printf"Initialization succeeded \ n");}List *CreateList (List *h) {int input; while(~SCANF ("%d",&Input)) {List *P=(List *) malloc (sizeof (List));if(!P) Exit (-1); P -Val=Input P -Next=H -Next H -Next=P } printf ("created successfully \ n");returnH;}voidPrintlist (List *h) {List *P=H -Next while(p) {if(p -Next) printf ("%d"P -Val); P=P -Next } printf ("\ n");}voidClearlist (List *h) {List *P= NULL; while(h) {p=H H=H -Next Free (p); } printf ("Empty" \ n ");}voidInvertlist (List *FList *P) {if(p -Next) Invertlist (P, p -Next); P -Next=F;} int main () {List *Head= NULL,*Tail= NULL; Initlist (&Head&tail);//The address of the incoming pointer, which is a level two pointerprintf"Reverse input data with EOF end flag \ n"); Head=CreateList (head);//input data to create a lead-tail linked listPrintlist (head); Invertlist (NULL, head);//recursive inversionprintf"inverse success \ n"); Printlist (tail);//The tail pointer becomes the head pointerClearlist (tail);return 0;}
"Data structure course work" single-linked list in-place inverse