Question: I am having trouble understanding this code. If someone could translate this to a flowchart, I would appreciate it. def areBracketsBalanced(expr): stack = [] #
I am having trouble understanding this code. If someone could translate this to a flowchart, I would appreciate it. 
def areBracketsBalanced(expr): stack = [] # Traversing the Expression for char in expr: if char in ["(", "{", "["]: # Push the element in the stack stack.append(char) else: # If current character is not opening # bracket, then it must be closing. # So stack cannot be empty at this point. if not stack: return false current_char = stack.pop() if current_char == '(': if char != ")": return false if current_char == '{': if char != "}": return false if current_char == '[': if char != "]": return false # Check Empty Stack if stack: return false return True # Driver Code if __name *__main__": expr = "{0}[]" # Function call if areBracketsBalanced (expr): print("Balanced") else: print("Not Balanced")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
