+ 2

Please , can someone explain to me what we have to do in this problem ?

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

19th Mar 2022, 10:45 PM
Programer F_K
Programer F_K - avatar
6 Answers
+ 4
In this task you need to make stack, then push each opening parenthesis to stack, when you find closing parenthesis then pop opening from stack. If your stack length is 0 then, string you cheched have same amount of opening and closening parenthesis, and you return true, if not you return false. This is what task is asked for
19th Mar 2022, 10:53 PM
PanicS
PanicS - avatar
19th Mar 2022, 10:54 PM
SoloProg
SoloProg - avatar
+ 2
PanicS oh yes I understand now . It's about making a stack . Thank you a lot 🙏
19th Mar 2022, 10:55 PM
Programer F_K
Programer F_K - avatar
+ 2
Programer F_K you have to apply push and pop techniques to check parenthesis are balanced or not.
19th Mar 2022, 10:57 PM
A͢J
A͢J - avatar
+ 1
Read first and second paragraph.
19th Mar 2022, 10:51 PM
A͢J
A͢J - avatar
+ 1
SoloProg okey . Thank you
19th Mar 2022, 10:57 PM
Programer F_K
Programer F_K - avatar