Given a Doubly circular linked list. The task is to find the position of an element in the list.
- Declare a temp pointer, and initialize it to head of the list.
- Iterate the loop until temp reaches start address (last node in the list, as it is in a circular fashion), check for the n element, whether present or not.
- If it is present, raise a flag, increment count and break the loop.
- At the last, as the last node is not visited yet check for the n element if present do step 3.
Below program illustrate the above approach:
Created circular doubly linked list is: 4 5 7 8 6 5 found at location 2
Time Complexity: As it uses linear search, so complexity is O(n).
- Doubly Circular Linked List | Set 2 (Deletion)
- Reverse a doubly circular linked list
- Doubly Circular Linked List | Set 1 (Introduction and Insertion)
- Convert an Array to a Circular Doubly Linked List
- Convert a given Binary Tree to Circular Doubly Linked List | Set 2
- Insertion at Specific Position in a Circular Doubly Linked List
- Circular Queue | Set 2 (Circular Linked List Implementation)
- Convert a Binary Tree to a Circular Doubly Link List
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- Difference between Singly linked list and Doubly linked list
- Convert singly linked list into circular linked list
- Check if a linked list is Circular Linked List
- Sorted merge of two sorted doubly circular linked lists
- QuickSort on Doubly Linked List
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.