This below, is an implementation of stack method for parentheses checker, this code works extremely fine except for 1 case.. where i input
(a+b)) or ())
just any type of such input where a closing bracket is left alone, even if the rest is balanced it counts it as balanced..why does that happen ? I couldn't find where the error is, maybe someone can help ? ^-^
You don't need all that, its just a counting problem.
int ct = 0;
if (input == '(' )
ct++
if (input == ')' )
ct--;
... after all input,
if(ct!= 0) its mismatched. you can add more logic to check for weird cases, for example, if ct is ever negative, its wrong, even if it balances. That will handle )))((( type mistakes that balance but are wrong. If being really smart, you will detect // and /* */ comment blocks and ignore inside (assuming c++ code being checked).
-- if I understood your code, I think your error is here.
if(top == nullptr) return;
this leaves the last value that was there in all the variables. It seems like something should be set so you can detect this?
By the way, your class has its organs outside.
`Stack' is `Node', but the members functions do seem to correspond to `Stack' and no one uses its state.
so you end with this abomination checker.isEmpty(top)