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
- Insert value in sorted way in a sorted doubly linked list
- Iterative Merge Sort for Linked List
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Recursive insertion and traversal linked list
- Given a linked list which is sorted, how will you insert in sorted way
- Construct a linked list from 2D matrix (Iterative Approach)
- Recursive function to delete k-th node from linked list
- Recursive approach for alternating split of Linked List
- Modify contents of Linked List - Recursive approach
- Recursive Approach to find nth node from the end in the linked list
- Print the alternate nodes of linked list (Iterative Method)
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.
Improved By : prerna saini