Implement the following specification for a client Boolean f
Solution
Please find the required program. Please see the comments against each line to understand the step.
bool Identical(stacktype<int> s1, stacktype<int> s2) {
int lh, rh;
int ret = 0;
if ( (lh = s1.pop()) == (rh = s2.pop()) ) { //check if both stacks top element is same or not
if ( !s1.isEmptyStack() and !s2.isEmptyStack() ) //if both tops are same, then pop the top element and recursively call Identical method on the rest elements of the stacks
return Identical(s1, s2);
else
ret = 1; //if both are not empty that means both are not same
}
s1.push(lh); //add the poped element back to stack to keep the stacks element back into it
s2.push(rh);
return ret;
}
