Given a Linked List, task is to check whether the Linked List is sorted in Descending order or not?
Input : 8 -> 7 -> 5 -> 2 -> 1 Output : Yes Explanation : In given linked list, starting from head, 8 > 7 > 5 > 2 > 1. So, it is sorted in reverse order Input : 24 -> 12 -> 9 -> 11 -> 8 -> 2 Output : No
Iterative Approach : Traverse the linked list from head to end. For every newly encountered element, check node -> data > node -> next -> data. If True, do same for each node else return 0 and Print “No”.
Time Complexity : O(N), where N is the length of linked list.
Recursive Approach :
Check Recursively that node -> data > node -> next -> data, If not, return 0 that is our terminated condition to come out from recursion else Call Check_List Function Recursively for next node.
- Program to check if an array is sorted or not (Iterative and Recursive)
- Search an element in a Linked List (Iterative and Recursive)
- Find Length of a Linked List (Iterative and Recursive)
- Check if a Linked List is Pairwise Sorted
- Merge K sorted Doubly Linked List in Sorted Order
- Insert value in sorted way in a sorted doubly linked list
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Given a linked list which is sorted, how will you insert in sorted way
- Recursive insertion and traversal linked list
- Iterative selection sort for linked list
- Iterative Merge Sort for Linked List
- Recursive approach for alternating split of Linked List
- Recursive function to delete k-th node from linked list
- Modify contents of Linked List - Recursive approach
- Recursive Approach to find nth node from the end in the 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.