Title: Data Structures with C Using STL
1Data Structures with CUsing STL
2What is a Stack?
- A stack is an ordered group of homogeneous items
(elements), in which the removal and addition of
stack items can take place only at the top of the
stack. - A stack is a LIFO last in, first out structure.
3Stack API
CLASS stack Constructors
ltstack.hgt
stack() Create an empty stack.
CLASS stack Operations
ltstack.hgt
bool empty() const Check whether the stack
is empty. Return true if it is empty, false
otherwise. void pop() Remove the item from
the top of the stack. Precond The stack is
not empty. Postcond Either the stack is
empty or the stack has a new topmost item from
the previous push. void push(const T
item) Insert the argument item at the top of
the stack. Postcond The stack has a new
item at the top.
4Stack API
CLASS stack Operations
ltstack.hgt
int size() const Return the number of items
on the stack. T top() Return a reference
to the value of the item at the top of the
stack. Precond The stack is not
empty. const T top() Constant version of
top.
5Tracing Client Code
V
letter
char letter V stackltchargt
charStack charStack.push(letter) charStack.push(
C) charStack.push(S) if ( !charStack.empty(
)) letter charStack.top()
charStack.pop() charStack.push(K) whi
le (!charStack.empty( )) letter
charStack.top() charStack.pop()
6Tracing Client Code
V
letter
char letter V stackltchargt charStack charStac
k.push(letter) charStack.push(C) charStack.pus
h(S) if ( !charStack.empty( ))
letter charStack.top()
charStack.pop() charStack.push(K) whi
le (!charStack.empty( )) letter
charStack.top() charStack.pop()
Private data
4
3
2
Top
1
-1
0
7Tracing Client Code
V
letter
char letter V stackltchargt charStack charStac
k.push(letter) charStack.push(C) charStack.pus
h(S) if ( !charStack.empty( ))
letter charStack.top()
charStack.pop() charStack.push(K) whi
le (!charStack.empty( )) letter
charStack.top() charStack.pop()
Private data
4
3
2
1
Top
0
'V'
0
8Tracing Client Code
V
letter
char letter V stackltchargt charStack charStac
k.push(letter) charStack.push(C) charStack.pus
h(S) if ( !charStack.empty( ))
letter charStack.top()
charStack.pop() charStack.push(K) whi
le (!charStack.empty( )) letter
charStack.top() charStack.pop()
Private data
4
3
2
1
Top
'C'
1
'V'
0
9Tracing Client Code
V
letter
char letter V stackltchargt charStack charStac
k.push(letter) charStack.push(C) charStack.pus
h(S) if ( !charStack.empty( ))
letter charStack.top()
charStack.pop() charStack.push(K) whi
le (!charStack.empty( )) letter
charStack.top() charStack.pop()
Private data
4
3
S'
2
1
Top
'C'
2
'V'
0
10Tracing Client Code
V
letter
char letter V stackltchargt charStack charStac
k.push(letter) charStack.push(C) charStack.pus
h(S) if ( !charStack.empty( ))
letter charStack.top()
charStack.pop() charStack.push(K) whi
le (!charStack.empty( )) letter
charStack.top() charStack.pop()
Private data
4
3
S'
2
1
Top
'C'
2
'V'
0
11Tracing Client Code
S
letter
char letter V stackltchargt charStack charStac
k.push(letter) charStack.push(C) charStack.pus
h(S) if ( !charStack.empty( ))
letter charStack.top()
charStack.pop() charStack.push(K) whi
le (!charStack.empty( )) letter
charStack.top() charStack.pop()
Private data
4
3
S
2
1
Top
'C'
1
'V'
0
12Tracing Client Code
S
letter
char letter V stackltchargt charStack charStac
k.push(letter) charStack.push(C) charStack.pus
h(S) if ( !charStack.empty( ))
letter charStack.top()
charStack.pop() charStack.push(K) whi
le (!charStack.empty( )) letter
charStack.top() charStack.pop()
Private data
4
3
K'
2
1
Top
'C'
2
'V'
0
13Tracing Client Code
S
letter
char letter V stackltchargt charStack charStack
.push(letter) charStack.push(C) charStack.push
(S) if ( !charStack.empty( )) letter
charStack.top() charStack.pop()
charStack.push(K) while
(!charStack.empty( )) letter
charStack.top() charStack.pop()
Private data
4
3
K'
2
1
Top
'C'
2
'V'
0
14Tracing Client Code
K
letter
char letter V stackltchargt charStack charStac
k.push(letter) charStack.push(C) charStack.pus
h(S) if ( !charStack.empty( ))
letter charStack.top()
charStack.pop() charStack.push(K) whi
le (!charStack.empty( )) letter
charStack.top() charStack.pop()
Private data
4
3
K'
2
1
Top
'C'
1
'V'
0
15Tracing Client Code
K
letter
char letter V stackltchargt charStack charStack
.push(letter) charStack.push(C) charStack.push
(S) if ( !charStack.empty( )) letter
charStack.top() charStack.pop()
charStack.push(K) while
(!charStack.empty( )) letter
charStack.top() charStack.pop()
Private data
4
3
K'
2
1
Top
'C'
1
'V'
0
16Tracing Client Code
C
letter
char letter V stackltchargt charStack charStac
k.push(letter) charStack.push(C) charStack.pus
h(S) if ( !charStack.empty( ))
letter charStack.top()
charStack.pop() charStack.push(K) whi
le (!charStack.empty( )) letter
charStack.top() charStack.pop()
Private data
4
3
K'
2
1
Top
C'
0
'V'
0
17Tracing Client Code
C
letter
char letter V stackltchargt charStack charStack
.push(letter) charStack.push(C) charStack.push
(S) if ( !charStack.empty( )) letter
charStack.top() charStack.pop()
charStack.push(K) while
(!charStack.empty( )) letter
charStack.top() charStack.pop()
Private data
4
3
K'
2
1
Top
C'
0
'V'
0
18Tracing Client Code
V
letter
char letter V stackltchargt charStack charStac
k.push(letter) charStack.push(C) charStack.pus
h(S) if ( !charStack.empty( ))
letter charStack.top()
charStack.pop() charStack.push(K) whi
le (!charStack.empty( )) letter
charStack.top() charStack.pop()
Private data
4
3
K'
2
1
Top
C'
-1
'V'
0
19Tracing Client Code
V
letter
char letter V stackltchargt charStack charStack
.push(letter) charStack.push(C) charStack.push
(S) if ( !charStack.empty( )) letter
charStack.top() charStack.pop()
charStack.push(K) while
(!charStack.empty( )) letter
charStack.top() charStack.pop()
Private data
4
3
K'
2
1
Top
C'
-1
'V'
0
20Example - Sorting using stacks
45
71
38
62
First value is 45 Put it on the Sorted Stack
Sorted Stack
temp Stack
21Example - Sorting using stacks
71
38
62
Next value is 71 Since 71 is larger, pop Sorted
Stack to determine where to put it placing each
value popped onto temp Stack.
45
Sorted Stack
temp Stack
22Example - Sorting using stacks
38
62
Next value is 71 Since 71 is larger, pop Sorted
Stack to determine where to put it placing each
value popped onto temp Stack.
When you insert 71 in correct spot on Sorted
Stack, pop temp Stack until empty putting each
item back onto Sorted Stack
45
71
Sorted Stack
temp Stack
23Example - Sorting using stacks
38
62
Next value is 71 Since 71 is larger, pop Sorted
Stack to determine where to put it placing each
value popped onto temp Stack. When you insert 71
in correct spot on Sorted Stack, pop temp Stack
until empty putting each item back onto Sorted
Stack
45
71
Sorted Stack
temp Stack
24Example - Sorting using stacks
38
62
Next value is 38 Since 38 is smaller than 45 (top
of Sorted Stack) Place it on top of Sorted Stack.
45
71
Sorted Stack
temp Stack
25Example - Sorting using stacks
62
Next value is 62 Pop 38 off Sorted Stack and push
onto tempStack.
38
45
71
Sorted Stack
temp Stack
26Example - Sorting using stacks
62
Next value is 62 Pop 38 off Sorted Stack and push
onto tempStack. Pop 45 off Sorted Stack and push
onto tempStack.
45
71
38
Sorted Stack
temp Stack
27Example - Sorting using stacks
62
Next value is 62 Pop 38 off Sorted Stack and push
onto tempStack. Pop 45 off Sorted Stack and push
onto tempStack. Push 62 onto Sorted Stack since
it is smaller than 71.
45
71
38
Sorted Stack
temp Stack
28Example - Sorting using stacks
Now pop temp Stack until empty pushing items one
at a time onto Sorted Stack.
45
62
71
38
Sorted Stack
temp Stack
29Example - Sorting using stacks
Now pop temp Stack until empty pushing items one
at a time onto Sorted Stack.
45
62
71
38
Sorted Stack
temp Stack
30Example - Sorting using stacks
Now pop temp Stack until empty pushing items one
at a time onto Sorted Stack.
38
45
62
71
Sorted Stack
temp Stack
31Function to sort input data
- template lttypename Tgt
- void sortInput(ListltTgt L)
- stack ltTgt Sorted, temp// stacks initialized to
empty - ListltTgtiterator curr, stop
- curr L.begin() // initialize iterators
- stop L.end()
-
-
32- // loop to process each item in the list
- while (curr ! stop)
- T stackTop, item
- item curr // get curr item of list L
- while (! Sorted.empty() Sorted.top() lt
item)) - stackTop Sorted.top() // get top item
from stack - Sorted.pop() // delete top of Sorted
stack - temp.push(stackTop) // push stackTop
onto temp stack -
- Sorted.push(item) // put item onto
Sorted stack - // put all items from temp back onto the Sorted
stack - while(! temp.empty())
- stackTop temp.top() // get top item of
temp - temp.pop() // delete top item of
temp - Sorted.push(stackTop) // put item from
temp onto Sorted -
- curr // update curr to
next item in list L -
33- // move items from stack back into the list
- while (!Sorted.empty())
- // save and remove top of Sorted stack
- stackTop Sorted.top()
- Sorted.pop()
- // place top of Sorted stack at rear of list
L - L.push_back(stackTop)
-
34Stack Implementation as vector
- template lttypename Tgt
- class stack
- public
- stack()
- // constructor, create an empty stack
-
- void push(const T item)
- // push (insert) item onto the stack
- // Postcond the stack has a new topmost
element and the - // stack size is increased by 1
- void pop()
- // remove the item from the top of the stack.
- // Precond the stack is not empty.
35Stack Implementation as vector-cont.
- T top()
- // return a reference to the element on the top
of the stack. - // Precond the stack is not empty.
- const T top() const
- // constant version of top()
- bool empty() const
- // determine whether the stack is empty
- int size() const
- // return the number of elements in the stack
- private
- vectorltTgt stackVector
- // a vector object maintains the stack items
and size
36Stack Implementation as vector-cont.
template lttypename Tgt stackltTgtstack()
template lttypename Tgt void stackltTgtpush(const
T item) stackVector.push_back(item) templa
te lttypename Tgt void stackltTgtpop()
stackVector.pop_back()
37Stack Implementation as vector-cont.
template lttypename Tgt T stackltTgttop() if
(empty()) return T() return
stackVector.back() template lttypename
Tgt const T stackltTgttop() const if (empty())
return const T() return stackVector.back()
38Stack Implementation as vector-cont.
template lttypename Tgt bool stackltTgtempty() r
eturn stackVector.empty() template lttypename
Tgt int stackltTgtsize() return
stackVector.size()
39Representation of Arithmetic Expressions
- Prefix Notation - operator precedes its
operands. A B - C D - Infix Notation - operator is between its
operands. ( A B) ( C - D ) - Postfix Notation - operator follows its operands.
A B C D -
40Stack Application 1Evaluation of Postfix
Expressions
- An Example
- 6 3 7 2 -
- 9
- 9 7 2 -
- 5
- 9 5
- 45
41Evaluation of Postfix Expressions
- Operands are placed onto the stack until their
operator is located. - Operators are executed when they are located.
- Pop stack to remove operands
- Evaluate expression
- Place result onto stack
42An Example - Stack is empty
5 2 - 4 6
stack operands
43An Example - Push 5
5 2 - 4 6
operands
operands. push (5)
5
44An Example - Push 2
5 2 - 4 6
operands
operands.push(2)
2
5
45An Example - Process -
5 2 - 4 6
operands
op2 operands.top() operands.pop() op1
operands.top() operands.pop() ans op1 -
op2 operands.push (ans)
op1 op2 ans
5
2
46An Example - Process -
5 2 - 4 6
operands
op2 operands.top() operands.pop() op1
operands.top() operands.pop() ans op1 -
op2 operands.push (ans)
Op1 Op2 Ans
5
2
47An Example - Process -
5 2 - 4 6
operands
op2 operands.top() operands.pop() op1
operands.top() operands.pop() ans op1 -
op2 operands.push (ans)
Op1 Op2 Ans
5
2
3
48An Example - Process -
5 2 - 4 6
operands
Private Data Top maxItems-1 . . .
3 2
1 items0
op2 operands.top() operands.pop() op1
operands.top() operands.pop() ans op1 -
op2 operands.push (ans)
0
Op1 Op2 Ans
2
3
3
5
2
3
49An Example - Push 4
5 2 - 4 6
operands
operands.push(4)
4
3
50An Example - Push 6
5 2 - 4 6
operands
operands.push(6)
6
4
3
51An Example - Process
5 2 - 4 6
operands
op2 operands.top() operands.pop() op1
operands.top() operands.pop() ans op1
op2 operands.push (ans)
4
Op1 Op2 Ans
3
6
52An Example - Process
5 2 - 4 6
operands
op2 operands.top() operands.pop() op1
operands.top() operands.pop() ans op1
op2 operands.push (ans)
Op1 Op2 Ans
3
4
6
53An Example - Process
5 2 - 4 6
operands
op2 operands.top() operands.pop() op1
operands.top() operands.pop() ans op1
op2 operands.push (ans)
Op1 Op2 Ans
3
4
6
10
54An Example - Process
5 2 - 4 6
operands
op2 operands.top() operands.pop() op1
operands.top() operands.pop() ans op1
op2 operands.push (ans)
10
Op1 Op2 Ans
3
4
6
10
55An Example - Process
5 2 - 4 6
operands
op2 operands.top() operands.pop() op1
operands.top() operands.pop() ans op1
op2 operands.push (ans)
Op1 Op2 Ans
3
10
56An Example - Process
5 2 - 4 6
operands
op2 operands.top() operands.pop() op1
operands.top() operands.pop() ans op1
op2 operands.push (ans)
Op1 Op2 Ans
3
10
57An Example - Process
5 2 - 4 6
operands
op2 operands.top() operands.pop() op1
operands.top() operands.pop() ans op1
op2 operands.push (ans)
Op1 Op2 Ans
3
10
30
58An Example - Process
5 2 - 4 6
operands
op2 operands.top() operands.pop() op1
operands.top() operands.pop() ans op1
op2 operands.push (ans)
Op1 Op2 Ans
30
3
10
30
59Stack Application 2Conversion from Infix to
Postfix
- Operands placed in postfix expression as they are
encountered. - Operators need to be stored on stack until they
should be executed. - Precedence
- Parentheses
- Current Operator pushed onto stack
- Dealing with the stack at end of expression
60Dealing with operators
- While the operator at the top of the stack must
be executed before the current operator, pop the
stack and place operator into postfix expression.
- If current token is open parentheses just push it
onto the stack, it acts as a barrier. The only
operator to remove it is a close parentheses. - If current token is a close parentheses, pop the
stack while top is not an open parentheses. Then
pop and discard the open parentheses. - Always push all current operators (except close
parentheses) onto the stack.
61How to finish processing after last token
- Pop all remaining operators off the stack after
the last token has been processed. Place each
operator onto the postfix expression as it is
popped.
62An Example Infix to Postfix
stackltchargt operator char token, stTop Cstring
postExpr bool done false
63An Example Infix to Postfix
operator
token
postExprtoken
A
done
false
stTop
postExpr
A
64An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
operator
token
done
false
stTop
postExpr
A
65An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
66An Example Infix to Postfix
postExprtoken
67An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
68An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
operator
token
done
false
stTop
postExpr
AB
69An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
70An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
operator
token
done
true
stTop
postExpr
AB
71An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
72An Example Infix to Postfix
postExprtoken
73An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
74An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
75An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
76An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
77An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
operator
token
-
done
false
stTop
postExpr
ABC
78An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
79An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
80An Example Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
-
81An Example Infix to Postfix
postExprtoken
-
82An Example Infix to Postfix
while (!operator.empty()) stTop
operator.top() operator.pop()
postExpr stTop
-
83An Example Infix to Postfix
while (!operator.empty()) stTop
operator.top() operator.pop()
postExpr stTop
84An Example Infix to Postfix
while (!operator.empty()) stTop
operator.top() operator.pop()
postExpr stTop
85Example 2 Infix to Postfix
stack operator char token, stTop Cstring
postExpr bool done false
86Example 2 Infix to Postfix
if (token '(' ) operator.push(token)
87Example 2 Infix to Postfix
postExprtoken
88Example 2 Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
89Example 2 Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
operator
90Example 2 Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
-
true
(
'('
A
91Example 2 Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
92Example 2 Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
-
93Example 2 Infix to Postfix
postExprtoken
94Example 2 Infix to Postfix
if (token ')' ) stTop
operator.top() while (stTop!'(' )
postExprstTop
operator.pop() stTop operator.top()
operator.pop() //
discard '('
95Example 2 Infix to Postfix
if (token ')' ) stTop
operator.top() while (stTop!'(' )
postExprstTop
operator.pop() stTop operator.top()
operator.pop() //
discard '('
96Example 2 Infix to Postfix
if (token ')' ) stTop
operator.top() while (stTop!'(' )
postExprstTop
operator.pop() stTop operator.top()
operator.pop() //
discard '('
97Example 2 Infix to Postfix
if (token ')' ) stTop
operator.top() while (stTop!'(' )
postExprstTop
operator.pop() stTop operator.top()
operator.pop() //
discard '('
)
false
(
('
AB-
98Example 2 Infix to Postfix
if (token ')' ) stTop
operator.top() while (stTop!'(' )
postExprstTop
operator.pop() stTop operator.top()
operator.pop() //
discard '('
99Example 2 Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
100Example 2 Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
/
101Example 2 Infix to Postfix
operator
token
if (token '(' ) operator.push(token)
'('
done
false
(
stTop
/
('
postExpr
AB-
102Example 2 Infix to Postfix
operator
token
postExprtoken
D
done
false
(
stTop
/
('
postExpr
AB-D
103Example 2 Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
operator
token
done
false
(
stTop
/
('
postExpr
AB-D
104Example 2 Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
operator
token
done
false
(
stTop
/
'('
postExpr
AB-D
105Example 2 Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
true
(
/
'('
AB-D
106Example 2 Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
true
(
/
'('
AB-D
107Example 2 Infix to Postfix
while (!operator.empty() !done) stTop
operator.top() if (precedence(stTop,
token) operator.pop() postExpr
stTop else done true
operator.push(token) done false
false
(
/
'('
AB-D
108Example 2 Infix to Postfix
postExprtoken
E
false
(
/
'('
AB-DE
109Example 2 Infix to Postfix
if (token ')' ) stTop
operator.top() while (stTop!'(' )
postExprstTop
operator.pop() stTop operator.top()
operator.pop() //
discard '('
)
false
(
/
''
AB-DE
110Example 2 Infix to Postfix
if (token ')' ) stTop
operator.top() while (stTop!'(' )
postExprstTop
operator.pop() stTop operator.top()
operator.pop() //
discard '('
)
false
(
/
''
AB-DE
111Example 2 Infix to Postfix
if (token ')' ) stTop
operator.top() while (stTop!'(' )
postExprstTop
operator.pop() stTop operator.top()
operator.pop() //
discard '('
)
false
(
/
'('
AB-DE
112Example 2 Infix to Postfix
operator
token
if (token ')' ) stTop
operator.top() while (stTop!'(' )
postExprstTop
operator.pop() stTop operator.top()
operator.pop() //
discard '('
)
done
false
(
stTop
/
'('
postExpr
AB-DE
113Example 2 Infix to Postfix
if (token ')' ) stTop
operator.top() while (stTop!'(' )
postExprstTop
operator.pop() stTop operator.top()
operator.pop() //
discard '('
)
false
/
'('
AB-DE
114Example 2 Infix to Postfix
while (!operator.empty()) stTop
operator.top() operator.pop()
postExpr stTop
operator
token
\0
done
false
stTop
/
'('
postExpr
AB-DE
115Example 2 Infix to Postfix
while (!operator.empty()) stTop
operator.top() operator.pop()
postExpr stTop
AB-DE/
116Example 2 Infix to Postfix
while (!operator.empty()) stTop
operator.top() operator.pop()
postExpr stTop
operator
token
\0
done
false
stTop
/
postExpr
AB-DE/