Iterate through a stack
I am working on a question.
Use a stack to process parenthesized expressions. When you seen an open
parenthesis, note that it was seen. When you see a close parenthesis after
an open parenthesis, pop elements down to and including the open
parenthesis of the stack. push a value onto the stack to indicate that a
parenthesized expression was replaced.
How is this even possible? This would require to iterate through a stack.
For instance, if the stack was composed of chars and initialized with
This is just (a test) to see.
I can pop off the top until I see a closed parenthesis and store each word
and push_front into a different container, etc. And then copy back into a
stack but that is indirectly solving the problem. I don't understand how
you can answer the problem without iterating through the stack and from my
understanding stack does not use iterators or subscripts so how is that
possible?
No comments:
Post a Comment