Use C to print two-way non-circular linked list (no leading node) in reverse order

Source: Internet
Author: User

Use C to print two-way non-circular linked list (no leading node) in reverse order

In my previous blog "", I constructed a bidirectional non-cyclic linked list and implemented forward printing. In my previous blog "printing the reverse order of a single-chain table in C Language", I also printed the reverse order of a single-chain table. In this blog, We can print two-way non-circular linked lists in reverse order, which is very simple to implement. The Code has been uploaded to https://github.com/chenyufeng1991/reversedoublelinkedlist.

The core code is as follows:

// Print a non-circular two-way linked list. This is actually a forward print void printList (Node * pNode) {if (pNode = NULL) {printf ("% s function execution, the linked list is empty. Print failed \ n ",__ FUNCTION _);} else {while (pNode! = NULL) {printf ("% d", pNode-> element); pNode = pNode-> next;} printf ("\ n ");}}
// Print the void ReversePrintList (Node * pNode) {Node * pMove; pMove = pNode; if (pNode = NULL) {printf ("% s function execution, the two-way non-cyclic linked list is empty and printing in reverse order failed \ n ",__ FUNCTION _);} else {// traverses the last node from the past to the next while (pMove-> next! = NULL) {pMove = pMove-> next;} // traverse from the back to the first node and print the node value while (pMove! = NULL) {printf ("% d", pMove-> element); pMove = pMove-> prior;} printf ("\ n % s function execution, bidirectional non-cyclic linked list printed in reverse order \ n ",__ FUNCTION __);}}
By carefully studying the code, we can find that if you want to reverse a linked list, using a two-way linked list is much easier than using a single-chain table.

Related Article

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.