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
Nesta página do site você pode assistir ao vídeo on-line Check if parenthesis are balanced using Stack| Java duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Coding Env 01 Janeiro 1970, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 1,694 vezes e gostou 20 espectadores. Boa visualização!