A single-linked list printing of algorithm exercises---linear table

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.