2016-03-08 33 views
-3

如何检查一个数组或链表是否被排序或没有使用C++?给定一组数字?有没有可用于检查的功能?如何检查链表是否使用C++排序?

+2

[性病::已排序(http://en.cppreference.com/w/cpp/algorithm/is_sorted) – Jarod42

+0

http://stackoverflow.com/questions/35182013/how-can- i-check-if-vector-elements-is-order-order- –

+1

Cody Grey刚刚发布的链接上的最佳答案。试着在这里用一些关键字搜索一下,然后再问:) – George

回答

3

只需使用std::is_sorted类似:

if (std::is_sorted(std::begin(linked_list), std::end(linked_list)) { 
    //... 
}