0

Please help me in solving this question...

Parentheses are balanced, if all opening parentheses have their corresponding closing parentheses. Given an expression as input, we need to find out whether the parentheses are balanced or not. For example, "(x+y)*(z-2*(6))" is balanced, while "7-(3(2*9))4) (1" is not balanced. The problem can be solved using a stack. Push each opening parenthesis to the stack and pop the last inserted opening parenthesis whenever a closing parenthesis is encountered. If the closing bracket does not correspond to the opening bracket, then stop and say that the brackets are not balanced. Also, after checking all the parentheses, we need to check the stack to be empty -- if it's not empty, then the parentheses are not balanced. Implement the balanced() function to return True if the parentheses in the given expression are balanced, and False if not. Sample Input: (a( ) eee) ) Sample Output: False

14th Oct 2022, 7:09 AM
Andery Adwin
Andery Adwin - avatar
8 Réponses
+ 2
Learn about "stack" and it's operations, how to use it... then it may is easy for you to understand and do this task...
14th Oct 2022, 8:01 AM
Jayakrishna 🇮🇳
+ 1
if you don't understand let me know the exact place
15th Oct 2022, 8:28 AM
Emmanuel Odukoya
Emmanuel Odukoya - avatar
+ 1
Excuse me can you tell answer for this problem. i need to complete it please
15th Oct 2022, 10:35 AM
Vidhya Sudha
0
i would have to post the code here first with comments on it. agree?
14th Oct 2022, 4:33 PM
Emmanuel Odukoya
Emmanuel Odukoya - avatar
0
Yes bro I agree...
14th Oct 2022, 4:53 PM
Andery Adwin
Andery Adwin - avatar
0
okay
15th Oct 2022, 8:26 AM
Emmanuel Odukoya
Emmanuel Odukoya - avatar
0
here is it with explanation as comments in the code: https://code.sololearn.com/cC96vXm6iK84/?ref=app
15th Oct 2022, 8:27 AM
Emmanuel Odukoya
Emmanuel Odukoya - avatar
0
like how?, explain
15th Oct 2022, 10:29 PM
Emmanuel Odukoya
Emmanuel Odukoya - avatar