What is a linked list, this data structure is made up of a group of node, which together represents a sequence. The list is the most common and simplest data structure, and it is the basis for implementing other data structures such as stack, queue, etc.
A linked list is easier to insert and delete than an array.
Node can be defined as follows:
typedef int ELEMENT_TYPE;TYPEDEF struct node *node_ptr;struct node {element_type element;node_ptr next;};
In addition to the question of the head node, I propose to add the head node for the following reasons:
1. No head node, delete the first node, accidentally lost the list2. There is no intuitive way to insert a head. 3. The usual delete operation, you must first find the previous node, if there is no head node, delete the first node is not the same.
Next focus on the implementation of single-linked list reversal, which is often a problem, the following is the C language implementation:
void List_reverse (list L) {if (L->next = = null) Return;node_ptr p = l->next, first = L->next;while (P! = null & ;& P->next! = NULL) {Node_ptr Next_node = P->next;p->next = Next_node->next;next_node->next = First;fi rst = Next_node;} L->next = First;}
As for the other operations are not listed, you can focus on my github:
Https://github.com/booirror/data-structures-and-algorithm-in-c
Second understanding single linked list and its reversal (reverse)