
6.22 | Data Structures and Algorithms Using C++
• When a ‘(‘ is processed, push it into a stack.
• When a ‘)’ is processed, pop it from the stack. is ‘(‘ matches with current ‘)’.
• If reading the expression is nished, but the stack is not empty, it means there are more ‘(‘ than ‘)’ in
the expression, then the input is invalid.
6.4.4.1 The ADT Stack
A stack is a collection of elements or items, for which the following operations are de ned:
• create(S) creates an empty stack S.
• isEmpty(S) is a predicate that returns “true’’ if S exists and is empty, and “false’’ otherwise.
• push(S,item) adds the given item to the stack S. ...