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
- 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
- Delete all Prime Nodes from a Circular Singly Linked List
- Sum and Product of the nodes of a Circular Singly Linked List which are divisible by K
- Find middle of singly linked list Recursively
- Find the common nodes in two singly linked list
- Difference between Singly linked list and Doubly linked list
- Circular Queue | Set 2 (Circular Linked List Implementation)
- Count minimum frequency elements in a linked list
- Maximum and Minimum element of a linked list which is divisible by a given number k
- Convert Singly Linked List to XOR Linked List
- Rearrange a given list such that it consists of alternating minimum maximum elements
- QuickSort 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.