Dynamic Implementation
The concept of a linked list in data structures addresses the limitations of fixed-size arrays by providing a dynamic and flexible way to allocate memory.
Introduction
In traditional programming, memory allocated for variables, like arrays, is fixed during compile time. For example, if an array A of size 100 is declared, it occupies memory for 100 elements, and this memory cannot be changed dynamically during program execution.
Linked List:
Linked List is a dynamic data structure, it is collection of special types of data structure called as nodes. Nodes are dynamically created during the run time as required, thus solving the problem of memory shortage or wastage. The node in the linked list generally consists of two parts: data part and address part.
Data/Information: This part stores the actual value or information associated with the node.
Pointer/Address: This part contains the address of the next node in the sequence. This pointer links one node to the next, forming a chain-like structure.
In linked list the chain of nodes as shown above forms a linked list as shown below:
As shown in the figure above, each node in the linked list holds the address of the next node in the linked list. The address in the last node is NULL, as no other node exists after that. Every linked list maintains a separate pointer called HEAD, the head pointer holds the address of the first node in the linked list, so the first node is also called a head node. The address in the head node is essential to traverse the linked list.
In C programming, we can use structure to represent a node as given below:
ADVANTAGES AND DISADVANTAGES
Linked list have many advantages and some of them are:
Linked list has following disadvantages