Check if parenthesis are balanced using Stack| Java

Published: 01 January 1970
on channel: Coding Env
1,694
20

Find if parenthesis are balanced for a given string using Stack in Java.

1) Create an empty character stack.
2) Traverse the string
If the current character is a starting bracket (‘(‘ or ‘{‘ or ‘[‘) then push it to stack.
If the current character is a closing bracket (‘}’, ‘]’, ‘)’), then pop the element from the stack and compare with current bracket. If it is not matching, it is not balanced.
One by one pop all characters from stack and put them back to string.
3) After complete traversal, if there is any bracket left in stack then “not balanced”

Code location: https://github.com/codingenv/Java/tre...

Programming questions on Java:    • Java Interview Programs  

Java Design Pattern:    • Java | OOPs Concepts  


On this page of the site you can watch the video online Check if parenthesis are balanced using Stack| Java with a duration of hours minute second in good quality, which was uploaded by the user Coding Env 01 January 1970, share the link with friends and acquaintances, this video has already been watched 1,694 times on youtube and it was liked by 20 viewers. Enjoy your viewing!