Two-way non-circular linked list using C language (no leading node)

Source: Internet
Author: User

Two-way non-circular linked list using C language (no leading node)

A two-way linked list is also called a double-Link Table. Each of its data nodes has two pointers pointing to direct successor and direct precursor respectively. Therefore, starting from any node in the two-way linked list, you can easily access its precursor nodes and successor nodes. People often construct a two-way circular linked list. Today we are standalone. First, try to construct a two-way non-circular linked list. Sample Code uploads to the https://github.com/chenyufeng1991/DoubleLinkedList.

Constructor:

typedef struct NodeList{    int element;    struct NodeList *prior;    struct NodeList *next;}Node;

Construct a bidirectional non-circular linked list:
// Create a Node * createList (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, linked list created successfully \ 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.