1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <iostream>
#include <cassert>
using namespace std;
bool isStrictlyIncreasing(int a[], int len); //prototype
int main()
{
int a[] = {0,1,2,3,4,5};
assert(isStrictlyIncreasing(a,6)== true);
int b[] = {0,0};
assert(isStrictlyIncreasing(b,4)== false);
int c[] = {2,3,4};
assert(isStrictlyIncreasing(c,4)== true);
int d[] = {4,3,2,1};
assert(isStrictlyIncreasing(d,4)== false);
int e[] = {-9092,-14,1,13,0};
assert(isStrictlyIncreasing(e,5)== false);
int f[] = {-1,9800,3,12,-9006};
assert(isStrictlyIncreasing(f,5)== false);
int g[] = {-88,0,1,88};
assert(isStrictlyIncreasing(g,4)== true);
cout << "All tests have successfully passed." << endl;
}
bool isStrictlyIncreasing(int a[], int len)
{
for(int i=1;i<len;++i)
{
if(a[i] <= a[--i])
{
return false;
}
}
return true;
}
|