![]() |
VOOZH | about |
Circular Doubly Linked List has properties of both Doubly Linked List and Circular Linked List in which two consecutive elements are linked or connected by previous and next pointer and the last node points to the first node by next pointer and also the first node points to the last node by the previous pointer. The program implements all the functions and operations that are possible on a doubly circular list following functions in a menu-driven program.
Approach: Each function (except display) takes the address of the pointer to the head i.e. the first element of the list. This allows us to change the address of the head pointer. The idea is the use only one pointer, which is of type node, to perform all the operations. node is the class that contains three data members. One member is of type int which stores data of the node and two members of type node*, one store's address of next element and other stores address of the previous element. This way it is possible to traverse the list in either direction. It is possible to modify, insert, delete search for the element using a single pointer.
Functions Covered:
Below is the C++ program to implement the above approach:
Output:
1. void insert_front (node **head):
2. void insert_end (node **head):
3. void insert_after (node **head):
4. void insert_before (node **head):
5. void delete_front (node **head):
6. void delete_end (node **head):
7. void delete_mid (node **head):
8. void search (node *head):
9. void reverse (node **head):