what is the need to check
s.top() !=’(’
s.top() will always be equal to ‘(’ as we are only pushing it into the stack.
I think s.empty() condition alone will work fine in the code.
and also tell how are the brackets following LIFO order?
what is the need to check
s.top() !=’(’
s.top() will always be equal to ‘(’ as we are only pushing it into the stack.
I think s.empty() condition alone will work fine in the code.
and also tell how are the brackets following LIFO order?
This is the basic problem we solve when we are introduced to stack. No one expects you to immediately get an idea about using stack here if you haven’t seen stack been used before. Consider this as theory, and use this for solving variations of problems using stack.
during the vedio sir told that this expresion s=" ( (a+b ) + (c+d ) ) " is following LIFO order . explain this ?
It’s LIFO because the bracket which comes last goes out first.
Say the bracket just before A+B goes out first then the bracket at the start of the expression.
yes the bracket before a+b goes out first but that is not the last bracket which goes in.
the last bracket which goes in is before c+d .
It’s a sub problem. On the current structure it is the last bracket that goes in. It’s not like you can add all the brackets, you have to remove them side by side.
can you elaborate what are you trying to say?
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.
can u explain me again i didn’t get that ?