Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 1.51 KB

README.md

File metadata and controls

39 lines (30 loc) · 1.51 KB

Parentheses_Checker

The following are some code to check if the given expression is balanced parenthesis or not
Balanced parentheses: "[()]{}{()()}"
UnBalanced parentheses: "[(])"

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”

The Codes are available in following lanugage:

  1. Python
  2. C
  3. JAVA

Run the codes

  1. For Python - python parent_checker.py
  2. For C - Compile the file using gcc parent_checker.c
    After that create an executable file using gcc -o parent_checker parent_checker.c
    After creating executable file, execute the file using parent_checker.exe
  3. For JAVA - Compile the file using javac Parent_checker.java
    After that run the file using java Parent_checker

Future additions:

Codes in other lanuage like C++, Javascript etc...