replace with following code(this code satisfies all the conditions i.e.
i).testInOrder verifies the result of inOrder.Since when if(a <= b && b <= c) is false it
skips the call to inOrder cause inOrder is certain to be false.When if(a <= b && b <= c) is true
the value returned is same as returned by inOrder to the testInOrder method i.e. true.
ii)."assume inOrder is an EXPENSIVE function call, so call it as FEW times as possible!":-the code doen't call inOrder at all if if(a <= b && b <= c) is false
).:-
the code:-
(it will work for sure only if you call it properly (resubmit the whole program if any error occurs.):-
bool testInOrder(int a, int b, int c)
{
if(a <= b && b <= c)
{
return inOrder(a, b, c); //inorder here return true /false
}
else
{
return false;
}
your code:-
bool testInOrder(int a, int b, int c)
{
inOrder(a, b, c); <-calls inOrder twice,first here then below
if(bool inOrder == true) <-on calling inOrder it wil return true * also / /bool keyword not required
{
}
else
return false;
}
*
i