the program i have to write involves a dynamically linked stack to evaluate if the grouping symbols '(' , ')' , '{' , '}' , '[[/B]' , '[B]]' in expressions are balanced. The expression is input through keyboard.
For example:
expression: {A+(B-C)*D} is balanced
expression: T+{(R+M)/G-V*L is not balanced
expression: )A( is not balanced
expression: (A) is balanced
I do not have to do anything to the variables and operators but just determine if the grouping symbols are balanced. The stipulations are that i have to use a stack and that i can not use a counter to simply count the number of grouping symbols because that would evaluate )A( as balanced.
what iv come up with so far is to take the input as a string, convert it to individual characters, input to a stack using a for loop with the length of the string as the cutout.
what i can't seem to figure out is how to evaluate if the expression is balanced using only the pop, push, and top functions allowed with stacks. The only thing i can come up with is a complicated nested if,switch, and while statements that i am only half sure will work so there must be a simpler way.
any help or point into the right direction is greatly appreciated