One: Topic
Reverse-Print the data in a single-linked list, assuming the pointer points to the start node of a single-linked list
Second: Ideas
1. You can use the recursive method to print data
2. You can use the array space, get the length, reverse print array
3. If you can, the linked list data using the head interpolation method, reverse order, and then the positive sequence printing can
Three: Algorithm implementation (here use method one: recursive implementation is easy to understand)
#define_crt_secure_no_warnings#include<stdio.h>#include<stdlib.h>#defineMAXSIZE 10#defineOK 1#defineERROR 0typedefintStatus;typedefstructNode {intdata; structnode*Next;} Lnode,*linklist;//Initialize linked list with head nodeStatus Initlist (linklist*L) {Lnode* p,*Q; //Initialize the head node.*l = (linklist) malloc (sizeof(Lnode)); if(*l = =NULL)returnERROR; (*L)->next =NULL; P= *L; The //head interpolation method inserts data 1-10, which means that the linked list data is created by 10-1 for(inti =0; i < MAXSIZE; i++) {Q= (lnode*) malloc (sizeof(Lnode)); Q->data = i +1; Q->next = p->Next; P->next =Q; } returnOK;}void Invertprint (linklist L) {if (l!=null) {invertprint (l->next); printf ("%d->", l->data); }}intMain () {linklist L; //initializing linked list dataInitlist (&m); //Print DataInvertprint (l->next); System ("Pause"); return 0;}
A single-linked list printing of algorithm exercises---linear table