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 ;}