std::is_sorted
提供: cppreference.com
![]() | このページは、Google 翻訳を使って英語版から機械翻訳されました。 翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
Defined in header <algorithm> | ||
template<class ForwardIt > bool is_sorted( ForwardIt first, ForwardIt last ); | (1) | (C++11およびそれ以降) |
template<class ForwardIt, class Compare > bool is_sorted( ForwardIt first, ForwardIt last, Compare comp ); | (2) | (C++11およびそれ以降) |
Checks if the elements in range [first, last)
are sorted in ascending order. The first version of the function uses operator< to compare the elements, the second uses the given comparison function comp
.
目次 |
[編集]パラメータ
first, last | - | 検討する要素の範囲 Original: the range of elements to examine The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
comp | - | 比較関数. 最初の値が二つ目の値より小さい 場合、 trueを返します. 比較関数のシグネチャは以下と同等でなければなりません. bool cmp(const Type1 &a, const Type2 &b); シグネチャは |
型の要件 | ||
-ForwardIt は ForwardIterator の要求を満足しなければなりません。 |
[編集]値を返します
true if the elements in the range are sorted in ascending order
[編集]複雑性
first
last
との間の距離の線形Original:
linear in the distance between
first
and last
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[編集]可能な実装
First version |
---|
template<class ForwardIt>bool is_sorted(ForwardIt first, ForwardIt last){returnstd::is_sorted_until(first, last)== last;} |
Second version |
template<class ForwardIt, class Compare>bool is_sorted(ForwardIt first, ForwardIt last, Compare comp){returnstd::is_sorted_until(first, last, comp)== last;} |
[編集]例
このコードを実行します
#include <iostream>#include <algorithm> int main(){constint N =5;int digits[N]={3, 1, 4, 1, 5}; for(auto i : digits)std::cout<< i <<' ';std::cout<<": is_sorted: "<< std::is_sorted(digits, digits+N)<<'\n'; std::sort(digits, digits+N); for(auto i : digits)std::cout<< i <<' ';std::cout<<": is_sorted: "<< std::is_sorted(digits, digits+N)<<'\n';}
出力:
3 1 4 1 5 : is_sorted: 0 1 1 3 4 5 : is_sorted: 1
[編集]参照
(C++11) | 最大のソート部分範囲を見つけることができます Original: finds the largest sorted subrange The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数テンプレート) |