whats wrong in my code !
plzz comment it out
Https://ide.codingblocks.com/s/258980
still its giving wrong output after chnaging it
actually the logic is not correct
for input (a+b+c) it will print duplicate
which is not correct
what you are doing insertin only openning braces
so in this case first you push ( and then when you got )
you return true
which gives wrong output
correct logic:
We iterate through the given expression and for each character in the expression, if the character is a open parenthesis β(β or any of the operators or operands, we push it to the stack. If the character is close parenthesis β)β, then pop characters from the stack till matching open parenthesis β(β is found.
Now for redundancy two condition will arise while popping-
- If immediate pop hits a open parenthesis β(β, then we have found a duplicate parenthesis. For example, (((a+b))+c) has duplicate brackets around a+b . When we reach second β)β after a+b, we have β (( β in the stack. Since the top of stack is a opening bracket, we conclude that there are duplicate brackets.
- If immediate pop doesnβt hit any operand(β*β, β+β, β/β, β-β) then it indicates the presence of unwanted brackets surrounded by expression. For instance, (a)+b contain unwanted () around a thus it is redundant.
I hope Iβve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
https://ide.codingblocks.com/s/277303 pleasew check it again its giving error and not right ouptput am unable to do it
I have corrected the syntax errors. Still your output is not correct. Very your approach from above.
You can refer this code
I hope Iβve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.