List or linked list is a collection of nodes/recodes linked with each other using pointer. A node data structure has at least a member to hold the current element value and a pointer to point to the next node.
Linked List data-structure
int node_value; /* value/data of this node */
struct _slist_node * next; /* point to next node */
In this example nodes will be object of structure slist_node. Node_value member will be used to hold a user value. Member “next” will be used to point the next member in the list.
The first node of the linked list is called head and last node is the tail. When there is no element both head = tail = null. A new node object is created from heap using malloc/new and added to the list by setting proper value of the next/previous pointer. When we need to delete a particular node, we modify the next/previous pointer of the neighboring node and delete the node from heap using free/delete. This is a vital advantage list over array. We can add or remove any node at any location and memory is allocated or de-allocated at the run time.
Allocate New node
new_node() function allocates new node for the given input value. It also takes care memory allocation error.