Print a single-chain table in reverse order using C language (Leading node)

Source: Internet
Author: User

Print a single-chain table in reverse order using C language (Leading node)

In my previous blog "printing a single linked list (with no leading node) in reverse order in C Language", I used to print a list with no leading node in reverse order, the overall idea is also very simple, that is, to traverse the original linked list in sequence, and then use the header insertion method to create a new linked list. The new linked list is the reverse order of the original linked list. In this blog, I will use the linked list of the leading node to implement reverse order. The idea is the same as above.

The core code is as follows:

/*** The overall idea is to retrieve a node and use the header insertion method to create a new linked list. The new linked list is created in reverse order. */Node * ReverseList (Node * pNode) {Node * reverseList; InitialList (& reverseList); // initialize the Node * pMove; Node * pInsert; pInsert = (Node *) malloc (sizeof (Node); memset (pInsert, 0, sizeof (Node); pInsert-> next = NULL; pMove = pNode-> next; while (pMove! = NULL) {// pInsert-> element = pMove-> element; pInsert-> next = reverseList-> next; reverseList-> next = pInsert; // Insert the Node and re-allocate the memory pInsert = (Node *) malloc (sizeof (Node); memset (pInsert, 0, sizeof (Node); pInsert-> next = NULL; pMove = pMove-> next;} printf ("% s FUNCTION execution. The single-chain table of the leading node is successfully created \ n" ,__ FUNCTION _); PrintList (reverseList ); return reverseList ;}

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.