How to check whether an array or a linked list is sorted or not given a set of numbers using c++?. Is there a function available to check that?
Asked
Active
Viewed 448 times
-3
-
2[std::is_sorted](http://en.cppreference.com/w/cpp/algorithm/is_sorted) – Jarod42 Mar 08 '16 at 12:31
-
http://stackoverflow.com/questions/35182013/how-can-i-check-if-vector-elements-are-in-order-consecutively – Cody Gray - on strike Mar 08 '16 at 12:46
-
1Top answer on the link Cody Gray just posted. Try to search a bit here with some keywords before asking :) – George Mar 08 '16 at 13:02
2 Answers
3
Simply use std::is_sorted
something like:
if (std::is_sorted(std::begin(linked_list), std::end(linked_list)) {
//...
}

Paul Evans
- 27,315
- 3
- 37
- 54
1
Check this stack overflow link hope you get it your answer.