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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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
- Sum and Product of the nodes of a Circular Singly Linked List which are divisible by K
- Delete all Prime Nodes from a Circular Singly Linked List
- Remove all the Even Digit Sum Nodes from a Circular Singly Linked List
- Remove all Fibonacci Nodes from a Circular Singly Linked List
- Remove all even parity nodes from a Doubly and Circular Singly Linked List
- Find the common nodes in two singly linked list
- Find middle of singly linked list Recursively
- 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
- QuickSort on Singly Linked List
- Sum of the nodes of a Singly Linked List
- Check if a linked list is Circular Linked List
- Binary Search on 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 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.