#include
#include
using namespace std;
bool checkExp(string s)
{
stackc;
for(int i=0;i<c.size();i++)
{
char curr=s[i];
if(curr==’(’)
{
c.push(curr);
}
else if(curr==’)’)
{
if(c.empty() || c.top()!=’(’ )
{
return false;
}
c.pop();
}
}
return true;
}
int main()
{
string expr;
cin>>expr;
bool isValid=checkExp(expr);
cout<<isValid;
return 0;
}
HERE IS THE SAME CODE IN THE VIDEO AND IT IS PRINTING 1 FOR BOTH TRUE AND FALSE CASES… KINDLY CHK AND ALSO UPDATE IN THE VIDEO
Given code in the video is not working
Hi,
the for loop in the function checkExp will never run in your code. You should mention s.size() rather than c.size() since you are traversing on the string.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.