206. Reverse Linked List

Source: Internet
Author: User

Reverse a linked list


1. Empty or single-element linked list returned directly

2. More than two elements

Set a new header T1;

Then iterate through the list, each traversing an element, is inserted into the T1;

The T2 is used to store the broken list.

Note that this is all address operations, such as T2=head, then head changes, T2 will change.


if (head==null| | Head->next==null)

return head;

t2=head->next;//such a head change will not affect T2.


head->next=t1;//Complete One operation

while (T2!=null)


head = t2;

T2 = t2->next;

T1->next = t3;

T1->next = head;

Head->next = t3; Insert operation


206. Reverse Linked List

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.