The advantage of using Circular Linked List is the last null pointer
is replaced and the pointer field of the last node points to the first
node, due to this circular arrangement the traversing become quite
easier.
The insertion and deletion in the first and middle are same as singly linked list except the last node.
Insertion
- Insertion in the last node
To
insert a node in the last position, insert the new node after the
current last node, and then change the pointer field of the new node to
point to the first node. Let the last node be last, the new node to be inserted to be new, the first node in the list to be first. The pointers used are ‘data’ for the data field, ‘next’ to the pointer field, the data to be inserted is ‘X ’then the insertion is
Last ? next = new
New ? next =first
Deletion
- Deletion in the last node
To
delete a node in the last position, change the pointer field of the
previous node to the current last to point the first node. Let the last
node be last, the previous node to the current last node to be pre, the first node in the list to be first. The pointers used are ‘data’ for the data field, ‘next’ to the pointer field, the data to be inserted is ‘X ’then the deletion is
Prev ? next = first
0 comments:
Post a Comment