Page 88 - DCAP407_DATA_STRUCTURE
P. 88
Unit 5: Introduction to Linked List
5.2 Representation of Linked List in Memory
The representation of a linked list in the memory is shown in figure 5.2. The linked list consists of three
nodes. Each node contains a data field and a link field. The data field consists of any data item that is
stored in a list such as, numbers, characters, strings, and so on. The link field holds the address of the
next element.
In the figure 5.2, HEAD Node holds the address of Node1 (0X80020), Node1 holds the address of Node2
(0X80041), and Node2 holds the address of Node3 (Null). “NULL” denotes a null pointer which is the
end of linked list or empty list.
Figure 5.2: Representation of a Linked List in Memory
HEAD Node
0X80025
Node1 Node2 Node3
11 0X80020 12 0X80041 13 NULL
0X80025 0X80020 0X80041
A linked list can be represented in memory with the following declaration:
struct new_list {
int element_value;
struct new_list *next_element;
}; node1, node2, node3
Here, a linked list named “new_list” is created. In “new_list” the data field named “element value” is
declared. The “element_value” can be an integer, a character, floating point, or double type. The
“new_list” also contains a link field named “*next_element” which points to the next node in the list.
The end of the structure containing three nodes (node1, node2, and node3) denotes the objects. They are
created to access the structure elements.
In a linked list, the HEAD node holds the address of the first node. When there are no
nodes present in a list, then the HEAD node will be equal to NULL and the list is
known as Empty list or NULL list.
5.3 Types of Linked Lists
The various types of linked list are:
1. Singly-linked list
2. Doubly-linked list
3. Circular singly-linked list
4. Circular doubly-linked list
LOVELY PROFESSIONAL UNIVERSITY 81