why we are adding s.top()!=’)’ for closing parenthesis as all cases are already covered by empty()? is just checking s.empty() not enough?
CPP - Stacks Question : Balanced Parenthesis why?
we write s.top()!=’)’
to check it is a balanced or not because in every balanced parenthesis first ‘(’ comes then ‘)’.
s.empty() we check at end after all iteration to make sure that all are not open
braces Ex: (((((()