bool isStrictlyIncreasing(const vector<int>& v)? Write a predicate function call
ID: 3552056 • Letter: B
Question
bool isStrictlyIncreasing(const vector<int>& v)?Write a predicate function called isStrictlyIncreasing that checks whether a vector of integers contains values that are in strictly increasing order. A declaration of the function is shown above. The function returns true if the elements are in strictly increasing order? otherwise it returns false. For example, it will return true for v = (2,4, 5, 6,8) and it will return false for (3, 4, 6, 6, 9).
bool isStrictlyIncreasing(const vector<int>& v)?
Write a predicate function called isStrictlyIncreasing that checks whether a vector of integers contains values that are in strictly increasing order. A declaration of the function is shown above. The function returns true if the elements are in strictly increasing order? otherwise it returns false. For example, it will return true for v = (2,4, 5, 6,8) and it will return false for (3, 4, 6, 6, 9).
Write a predicate function called isStrictlyIncreasing that checks whether a vector of integers contains values that are in strictly increasing order. A declaration of the function is shown above. The function returns true if the elements are in strictly increasing order? otherwise it returns false. For example, it will return true for v = (2,4, 5, 6,8) and it will return false for (3, 4, 6, 6, 9).
Explanation / Answer
bool isStrictlyIncreasing(const vector<int>& v)
{
for(int i=1; i<v.size(); i++)
{
if(v[i]<=v[i-1])
return false;
}
return true;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.