In Above code why we have added top()!=’(’ this line since there is only one condition to enter data into stack that is when character is ( so whenever there is an element it will always be equal to ( .So why to add this line
Bracket Balance using stack
you question is not clear to me
you have messed up all sentences in single line
please clearly explain your question
the algorithm of question you have asked is
Algorithm:
- Declare a character stack S.
- Now traverse the expression string exp.
- If the current character is a starting bracket ( ‘(‘ or ‘{‘ or ‘[‘ ) then push it to stack.
- If the current character is a closing bracket ( ‘)’ or ‘}’ or ‘]’ ) then pop from stack and if the popped character is the matching starting bracket then fine else parenthesis are not balanced.
- After complete traversal, if there is some starting bracket left in stack then “not balanced”
My question is simple that is why we have added this line of code top()!=( there is no need to add it ??
My question is simple that is why we have added this line of code top()!=( there is no need to add it ??