Solution Review: Check If List Is Sorted
This lesson will explain how to check if a list is sorted.
We'll cover the following
Solution: Use a Loop
Use a while loop that iterates over the length of the list and checks if the previous element in the list is less than the next element. If so, a variable flag is set to true. If the flag is false, a list is sorted and vice versa.
The following illustrations explain the concept of sorting a list.
Case 1: If the list is sorted
Get hands-on with 1200+ tech skills courses.