Single Linked List
Single list consists of nodes which contain only one pointer and a data.
To insert the nodes, we can use 4 methods:
- The new node is inserted in the beginning
- The new node is inserted in the end
- The new node is inserted after given node
- The new node is inserted before given node.
This is the logic example of the new node that is inserted in the beginning assuming that there is a linked list containing 10,35,27. We want to insert 31.
To delete a value, first we need to find the location of node which store the value we want to delete, remove it, and connect the remaining linked list.
This is the logic example of deleting the node in the beginning. In this example, we want to delete 31.
Circular Single Linked List
In circular, last node contains a pointer to the first node. There is no storing of NULL values in the list.
Double Linked List
Double linked list is also known as two-way linked list, because the nodes contain two pointer, one pointer points to the next node, the other one points to the previous node.
The way to insert data is the same like in single list, first we should allocate the new node and assign a value to it, then we connect the new node with the existing linked list.
To delete a value, there are 4 things that we need to pay attention :
- The node to be deleted is the only node in the linked list
- The node to be deleted is head
- The node to be deleted is tail
- The node to be deleted is not head or tail
Circular Double Linked List
In circular, the first node contains a pointer to the last node and the last node contains a pointer to the first node.
Tidak ada komentar:
Posting Komentar