Top Banner
Algorithms, 4 th Edition · Robert Sedgewick and Kevin Wayne · Copyright © 2002–2011 · February 23, 2012 4:05:36 PM Algorithms F O U R T H E D I T I O N R O B E R T S E D G E W I C K K E V I N W AY N E 1.3 DIJKSTRA'S TWO-STACK ALGORITHM click to begin demo
42

DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Mar 09, 2021

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Algorithms, 4th Edition · Robert Sedgewick and Kevin Wayne · Copyright © 2002–2011 · February 23, 2012 4:05:36 PM

AlgorithmsF O U R T H E D I T I O N

R O B E R T S E D G E W I C K K E V I N W A Y N E

1.3 DIJKSTRA'S TWO-STACK ALGORITHM

click to begin demo

Page 2: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

value stack operator stack

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

2

Dijkstra's two-stack algorithm

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

operand operator

infix expression(fully parenthesized)

Page 3: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

value stack operator stack

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

3

Dijkstra's two-stack algorithm

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

Page 4: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

4

Dijkstra's two-stack algorithm

+ ( ( 2 + 3 ) * ( 4 * 5 ) ) )1

value stack operator stack

Page 5: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

5

Dijkstra's two-stack algorithm

+ ( ( 2 + 3 ) * ( 4 * 5 ) ) )

1

value stack operator stack

Page 6: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

6

Dijkstra's two-stack algorithm

( ( 2 + 3 ) * ( 4 * 5 ) ) )

1

value stack operator stack

+

Page 7: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

7

Dijkstra's two-stack algorithm

( ( 2 + 3 ) * ( 4 * 5 ) ) )

1

value stack operator stack

+

Page 8: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

8

Dijkstra's two-stack algorithm

( ( 2 + 3 ) * ( 4 * 5 ) ) )

1

value stack operator stack

+

Page 9: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

9

Dijkstra's two-stack algorithm

2 + 3 ) * ( 4 * 5 ) ) )

1

value stack operator stack

+

(

Page 10: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

10

Dijkstra's two-stack algorithm

+ 3 ) * ( 4 * 5 ) ) )

1

value stack operator stack

+

2

Page 11: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

11

Dijkstra's two-stack algorithm

+ 3 ) * ( 4 * 5 ) ) )

1

value stack operator stack

+

2

Page 12: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

12

Dijkstra's two-stack algorithm

2

3 ) * ( 4 * 5 ) ) )

1

value stack operator stack

+

+

Page 13: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

13

Dijkstra's two-stack algorithm

2

3 ) * ( 4 * 5 ) ) )

1

value stack operator stack

+

+

Page 14: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

14

Dijkstra's two-stack algorithm

2 +

) * ( 4 * 5 ) ) )

1

value stack operator stack

+

3

Page 15: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

15

Dijkstra's two-stack algorithm

2 +

) * ( 4 * 5 ) ) )

1

value stack operator stack

+

3

Page 16: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

16

Dijkstra's two-stack algorithm

2 +

3

* ( 4 * 5 ) ) )

1

value stack operator stack

+

)

Page 17: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

17

Dijkstra's two-stack algorithm

2+3

* ( 4 * 5 ) ) )

1

value stack operator stack

+

Page 18: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

18

Dijkstra's two-stack algorithm

* ( 4 * 5 ) ) )

1

value stack operator stack

+

2+3 = 5

Page 19: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

19

Dijkstra's two-stack algorithm

* ( 4 * 5 ) ) )

1

value stack operator stack

+

5

Page 20: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

20

Dijkstra's two-stack algorithm

( 4 * 5 ) ) )

1

value stack operator stack

+

5

*

Page 21: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

21

Dijkstra's two-stack algorithm

( 4 * 5 ) ) )

1

value stack operator stack

+

5 *

Page 22: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

22

Dijkstra's two-stack algorithm

*

( 4 * 5 ) ) )

1

value stack operator stack

+

5

Page 23: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

23

Dijkstra's two-stack algorithm

*

* 5 ) ) )

1

value stack operator stack

+

5

4

Page 24: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

24

Dijkstra's two-stack algorithm

*

* 5 ) ) )

1

value stack operator stack

+

5

4

Page 25: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

25

Dijkstra's two-stack algorithm

*

4

* 5 ) ) )

1

value stack operator stack

+

5

Page 26: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

26

Dijkstra's two-stack algorithm

*

4 *

5 ) ) )

1

value stack operator stack

+

5

Page 27: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

27

Dijkstra's two-stack algorithm

*

4 *

) ) )

1

value stack operator stack

+

5

5

Page 28: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

28

Dijkstra's two-stack algorithm

*

4 *

) ) )

1

value stack operator stack

+

5

5

Page 29: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

29

Dijkstra's two-stack algorithm

*

4 *

5

) )

1

value stack operator stack

+

5

)

Page 30: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

30

Dijkstra's two-stack algorithm

*

4*5

) )

1

value stack operator stack

+

5

Page 31: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

31

Dijkstra's two-stack algorithm

*

4*5

) )

1

value stack operator stack

+

5

= 20

Page 32: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

32

Dijkstra's two-stack algorithm

*

) )

1

value stack operator stack

+

5

20

Page 33: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

33

Dijkstra's two-stack algorithm

*

)

1

value stack operator stack

+

5

20

)

Page 34: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

34

Dijkstra's two-stack algorithm

*

)

1

value stack operator stack

+

520

Page 35: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

35

Dijkstra's two-stack algorithm

*

)

1

value stack operator stack

+

520 = 100

Page 36: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

36

Dijkstra's two-stack algorithm

)

1

value stack operator stack

+

100

Page 37: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

37

Dijkstra's two-stack algorithm

)

1

value stack operator stack

+

100

Page 38: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

38

Dijkstra's two-stack algorithm

1

value stack operator stack

+100

Page 39: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

39

Dijkstra's two-stack algorithm

1

value stack operator stack

+100 = 101

Page 40: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

40

Dijkstra's two-stack algorithm

value stack operator stack

101

Page 41: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

41

Dijkstra's two-stack algorithm

value stack operator stack

101

Page 42: DIJKSTRA S TWO-STACK ALGORITHMfpl.cs.depaul.edu/jriely/ds2/extras/demos/13DemoDijkstra...click to begin demo Value: push onto the value stack. Operator: push onto the operator stack.

Value: push onto the value stack.Operator: push onto the operator stack.Left parenthesis: ignore.Right parenthesis: pop operator and two values; push the result ofapplying that operator to those values onto the operand stack.

( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )

42

Dijkstra's two-stack algorithm

result

101