-3
我需要檢查數組是否使用std::is_sorted()
函數排序。我不知道如何使用begin()
和end()
,所以我只是將數組傳遞給函數。如何在C++中使用is_sorted函數檢查數組是否被排序?
void sorted(bool value){
if(value)
cout << "Array is sorted" << endl;
else
cout << "Array is not sorted" << endl;
}
int main(){
int a[10], i;
cout << "Enter the sequence" << endl;
for(i=0; i<5; i++){
cin >> a[i];
}
bool value = is_sorted(a);
sorted(value);
return 0;
}
當我這樣做,雖然我得到這樣
錯誤沒有匹配的呼籲已排序功能
誤差範圍指出,沒有匹配的調用is_sorted函數。 –
'bool value = std :: is_sorted(a,a + 5);'別忘了'#include'。哦,你是不是真的想要聲明一個包含10個元素的數組,然後只填寫其中的5個? –
獲取副本,對副本進行排序,與原始副本進行比較 - > set bool –