2016-03-08 34 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)) { 
    //... 
}