A program to check for balanced parenthesis with and without using stack is discussed here. You can develop a parenthesis checker without using the stack as well. But using a stack can have several advantages.
[]
,{}
and()
and verify that they are correctly nested.Example:nnInput: ((()))nOutput: 1nnInput: ()((nOutput: -1n
The algorithm to check for balanced parenthesis with a stack is given below
@@coding::1@@
The algorithm to check for balanced parenthesis with a stack is given below.
@@coding::2@@
Recommended Programs