C. Create a single-chain table (Leading node) by using the header plug and tail plug)

Source: Internet
Author: User

C. Create a single-chain table (Leading node) by using the header plug and tail plug)

In my previous blog titled "C Implementation of the header plug-in and tail plug-in method to build a single-chain table (no leading node) it details how to use the header plug-in and tail plug-in to create a single-chain table with no leading nodes. However, in actual use, we use the most single-chain table with leading nodes. Today, we will implement the head plug and tail plug of the linked list of the leading node.

The core code is as follows:

// Create a single-chain table with the leading Node (tail Insertion Method) void CreateListTailInsert (Node * pNode) {/*** even if the number entered at the beginning is less than or equal to 0, the single-chain table of the lead node is created successfully, but the single-chain table is empty, that is, there are no other nodes except the header node. */Node * pInsert; Node * pMove; pInsert = (Node *) malloc (sizeof (Node); // check whether the allocated memory is successfully pInsert = NULL? Memset (pInsert, 0, sizeof (Node); pInsert-> next = NULL; scanf ("% d", & (pInsert-> element); pMove = pNode; while (pInsert-> element> 0) {pMove-> next = pInsert; pMove = pInsert; // pMove always points to the last Node pInsert = (Node *) malloc (sizeof (Node); // you need to check whether the allocated memory is successfully pInsert = NULL? Memset (pInsert, 0, sizeof (Node); pInsert-> next = NULL; scanf ("% d", & (pInsert-> element ));} printf ("% s FUNCTION execution, the single-chain table of the leading node is successfully created by means of the End Plug \ n" ,__ FUNCTION __);} // create a single-chain table with the leading Node (header Insertion Method) void CreateListHeadInsert (Node * pNode) {Node * pInsert; pInsert = (Node *) malloc (sizeof (Node )); memset (pInsert, 0, sizeof (Node); pInsert-> next = NULL; scanf ("% d", & (pInsert-> element )); while (pInsert-> element> 0) {pInsert-> next = pNode-> next; pNode-> next = pInsert; pInsert = (Node *) malloc (sizeof (Node); memset (pInsert, 0, sizeof (Node); pInsert-> next = NULL; scanf ("% d ", & (pInsert-> element);} printf ("% s FUNCTION execution. The single-chain table at the leading node is successfully created using the header Insertion Method \ n" ,__ FUNCTION __);}

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.