Reverse order of single linked list

Source: Internet
Author: User

Inverse single linked list (head insertion method for lead node)

void reverse (linklist L)//chain header pointer does not need to change; function set to no return value

{

Lnode*p,*q;

p= l->next; A linked list that does not lead the node and contains all the source data

l->next=null; Empty the original chain table

Construction of new linked list by head interpolation

while (p!= NULL)//has finished processing all the nodes to be inserted.

{

Q=p; Q Point to the node to be inserted

p=p->next; P points to the remaining not inserted nodes outside of the node to be inserted

q->next=l->next; 3

l->next=q; 4

3, 42: Insert new node using head interpolation

}

}

Note: You can handle the following special cases

1. Empty linked list

2. Only one node

3. The above two situations can also be specially dealt with in the function

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.