Given a singly circular linked list of nodes. The task is to find the smallest and largest elements in the circular linked list.
Input : List = 99->11->22->33->44->55->66 Output : Minimum = 11, Maximum = 99 Input : List = 12->11->9->33->125->6->99 Output : Minimum = 6, Maximum = 125
The idea is to traverse the circular linked list while last node is not reached and initialise the max and min variable to INT_MIN and INT_MAX respectively. After that check a condition that if max value is less then head value then head value is assign to max or min value is greater then head value then head value is assign to min otherwise head point to next node. Continue this process until last node.
Below is the implementation of the above approach:
Initial List: 99 11 22 33 44 55 66 Minimum = 11, Maximum = 99
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Minimum and Maximum Prime Numbers of a Singly Linked List
- Find smallest and largest elements in singly linked list
- Circular Singly Linked List | Insertion
- Convert singly linked list into circular linked list
- Remove all Fibonacci Nodes from a Circular Singly Linked List
- Sum and Product of the nodes of a Circular Singly Linked List which are divisible by K
- Remove all the Even Digit Sum Nodes from a Circular Singly Linked List
- Delete all Prime Nodes from a Circular Singly Linked List
- Remove all even parity nodes from a Doubly and Circular Singly Linked List
- Find middle of singly linked list Recursively
- Find the common nodes in two singly linked list
- Circular Queue | Set 2 (Circular Linked List Implementation)
- Difference between Singly linked list and Doubly linked list
- Maximum and Minimum element of a linked list which is divisible by a given number k
- Count minimum frequency elements in a linked list
- Convert Singly Linked List to XOR Linked List
- Sum of the nodes of a Singly Linked List
- QuickSort on Singly Linked List
- Check if a linked list is Circular Linked List
- Implement a stack using singly 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 firstname.lastname@example.org. 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.