C. Implement the header insertion and tail insertion methods to build a non-cyclic double-stranded table (no leading node)

Source: Internet
Author: User

C. Implement the header insertion and tail insertion methods to build a non-cyclic double-stranded table (no leading node)

In practice, double-stranded tables are much more convenient and flexible than single-linked tables. For the basic operations on non-cyclic double-stranded tables with no leading nodes, I have detailed implementation in the article "basic operations on two-way non-cyclic linked list with no leading node" in C language. Today, we will use two different methods of header insertion and tail insertion to create a double-stranded table.

The core code is as follows:

 

// Create a non-cyclic two-way linked list Node * TailInsertCreateList (Node * pNode) {Node * pInsert; Node * pMove; pInsert = (Node *) malloc (sizeof (Node); memset (pInsert, 0, sizeof (Node); pInsert-> next = NULL; pInsert-> prior = NULL; scanf ("% d", & (pInsert-> element); pMove = pNode; if (pInsert-> element <= 0) {printf ("% s function execution, the input data is invalid. Create a linked list to stop \ n ",__ FUNCTION _); return NULL;} while (pInsert-> element> 0) {if (pNode = NULL) {pNode = pInsert; pMove = pNode;} else {pMove-> next = pInsert; pInsert-> prior = pMove; pMove = pMove-> next;} pInsert = (Node *) malloc (sizeof (Node); memset (pInsert, 0, sizeof (Node); pInsert-> next = NULL; pInsert-> prior = NULL; scanf ("% d", & (pInsert-> element);} printf ("% s FUNCTION execution. The linked list is successfully created by the end-Insertion Method \ n" ,__ FUNCTION __); return pNode;} // create a non-circular bidirectional linked list Node * HeadInsertCreateList (Node * pNode) {Node * pInsert; pInsert = (Node *) malloc (sizeof (Node); memset (pInsert, 0, sizeof (Node); pInsert-> next = NULL; pInsert-> prior = NULL; scanf ("% d", & (pInsert-> element); if (pInsert-> element <= 0) {printf ("% s function execution, illegal input data, create a linked list to stop \ n ",__ FUNCTION _); return NULL;} while (pInsert-> element> 0) {if (pNode = NULL) {pNode = pInsert ;} else {pInsert-> next = pNode; pNode-> prior = pInsert; pNode = pInsert;} pInsert = (Node *) malloc (sizeof (Node); memset (pInsert, 0, sizeof (Node); pInsert-> next = NULL; pInsert-> prior = NULL; scanf ("% d", & (pInsert-> element ));} printf ("% s FUNCTION execution, the head plug method successfully creates the linked list \ n" ,__ FUNCTION _); return pNode ;}

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.