# Algorithm problem: Recursive reverse order of linked list

Source: Internet
Author: User

``#include <iostream>using namespace STD;structnode{intData    Node *next; Node (intD =int()):d ATA (d), next (NULL) {}};classclist{ Public: Clist (intA[],intN): First (NULL) {inti =0; Node *p = NULL; for(; i < n; i++) {Node *s =NewNode (A[i]);if(first = = NULL)                {first = s;            p = First; }Else{S->next = p->next;            P->next = s; }        }    }voidRelea ()//recursive reverse order. {Relea (Null,first); }voidPrintf () {Node *p = first; while(P! = NULL) {cout<< P->data <<"--->";        p = p->next; }cout<< Endl; }Private:voidRelea (Node *prv,node *t)//recursion in reverse order, feel nothing so mean. {if(T->next = = NULL) {first = t;return; }Else{PRV = t; Node *p = t->next;if(PRV = = first)            {prv->next = NULL;            } Relea (Prv,p);        P->next = PRV; }    }Private: Node *first;};intMain () {intA[] = {1,2,3,4,5,6,7,8,9}; Clist List1 (A,sizeof(a)/sizeof(int)); List1. Printf ();//Normal linked list. List1.relea (); List1. Printf ();//list after reverse order.     return 0;}``

Algorithm problem: Recursive reverse order of linked list

Related Keywords:

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.