-3

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?

Vishnu N K
  • 1,400
  • 1
  • 8
  • 17

2 Answers2

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.

How do I code a function to test if a linked list is sorted

Community
  • 1
  • 1
Bhupesh
  • 883
  • 7
  • 16