1 2 2 3 3 4 Must Get Same Answer As Manual Solution! Preserve - - PowerPoint PPT Presentation

1 2 2 3 3 4
SMART_READER_LITE
LIVE PREVIEW

1 2 2 3 3 4 Must Get Same Answer As Manual Solution! Preserve - - PowerPoint PPT Presentation

1 2 2 3 3 4 Must Get Same Answer As Manual Solution! Preserve The Mathematical Order Of Operations 69 ? 5 + 2 ^ 3 ^ 2 = _______ 517 ? Other ? 5 Maybe A Spreadsheet Will Help? 5 + 2 ^ 3 ^ 2 = _______ 69 ? 517 ? Maybe Not! 6


slide-1
SLIDE 1

1

slide-2
SLIDE 2

2 2

slide-3
SLIDE 3

3 3

slide-4
SLIDE 4

4

slide-5
SLIDE 5

Must Get Same Answer As Manual Solution!

Preserve The Mathematical Order Of Operations

5 + 2 ^ 3 ^ 2 = _______

69 ? 517 ? Other ?

5

slide-6
SLIDE 6

Maybe A Spreadsheet Will Help?

69 ? 517 ?

Maybe Not!

5 + 2 ^ 3 ^ 2 = _______

6

slide-7
SLIDE 7

Create A Valid Postfix Expression

Step 3

Preserve The Mathematical Order Of Operations

+

  • *

/ ^ ( )

# 1 Innermost First Parenthes, Brackets, Braces # 2 Right To Left # 4 Left To Right # 4 Left To Right # 3 Left To Right # 3 Left To Right

7

slide-8
SLIDE 8

Create Valid Postfix Expression Step 2

Preserve The Mathematical Order Of Operations

1 | 5 + 2 ^ 3 ^ 2 2 | ( 2 + 3 ) * (5 – 2) 3 | 3 * 2 + 3 – 4 / 2 / 2 - 3 8 4 | ( 3 + 2 ^ 3 ^ 2 / {4 * [ 5 – 4 ] -1 } ) * 2

5 + 2 ^ 3 ^ 2

Create Postfix By Hand – Must Be Able To Do So To Verify Correctness Of Algorithm

Infix Prefix Postfix

5 2 3 2 5 2 3 2

slide-9
SLIDE 9

9

slide-10
SLIDE 10

5 2 3 2

10

5 + 2 ^ 3 ^ 2

1 – Write Down All Of The Operands

Infix Prefix Postfix

5 2 3 2

slide-11
SLIDE 11

5 2 3 2^

11

5 + 2 ^ 3 ^ 2

2 – Solve As If Doing Mathematically – Order Of Operations

Infix Prefix Postfix

5 2 ^3 2

Put Operator In Front Of Respective Operands For Prefix Put Operator In Rear Of Respective Operands For Prefix

slide-12
SLIDE 12

5 + 2 ^ 3 ^ 2 5 2 3 2^^

12 2 – Solve As If Doing Mathematically – Order Of Operations

Infix Prefix Postfix

5 ^2 ^3 2 5 2 3 2^ 5 2 ^3 2

slide-13
SLIDE 13

5 2 3 2^^+

13

5 + 2 ^ 3 ^ 2

2 – Solve As If Doing Mathematically – Order Of Operations

Infix Prefix Postfix

+5 ^2 ^3 2 5 2 3 2^^ 5 ^2 ^3 2

slide-14
SLIDE 14

14

slide-15
SLIDE 15

( 2 + 3 ) * ( 5 – 2 )

15

Infix Prefix Postfix

+ 2 3 5 2 2 3 + 5 2 2 3 5 2 2 3 5 2

Solve As If Doing Mathematically – Order Of Operations

slide-16
SLIDE 16

( 2 + 3 ) * ( 5 – 2 )

16

Infix Prefix Postfix

+ 2 3

  • 5

2 2 3 + 5 2- + 2 3 5 2 2 3 + 5 2

Solve As If Doing Mathematically – Order Of Operations

slide-17
SLIDE 17

( 2 + 3 ) * ( 5 – 2 )

17

Infix Prefix Postfix

* + 2 3

  • 5 2

2 3 + 5 2 - * + 2 3

  • 5 2

2 3 + 5 2-

Solve As If Doing Mathematically – Order Of Operations

slide-18
SLIDE 18

18

slide-19
SLIDE 19

19

Infix Prefix Postfix

3 * 2 + 3 – 4 / 2 / 2 - 3 3 2 3 4 2 2 3 3 2 3 4 2 2 3 * 3 2 3 4 2 2 3 3 2* 3 4 2 2 3

Solve As If Doing Mathematically – Order Of Operations

slide-20
SLIDE 20

* 3 2 3 4 2 2 3

20

Infix Prefix Postfix

3 * 2 + 3 – 4 / 2 / 2 - 3 3 2* 3 4 2 2 3 * 3 2 3 /4 2 2 3 3 2* 3 4 2/ 2 3

Solve As If Doing Mathematically – Order Of Operations

slide-21
SLIDE 21

21

Infix Prefix Postfix

3 * 2 + 3 – 4 / 2 / 2 - 3 * 3 2 3 //4 2 2 3 3 2* 3 4 2/ 2/ 3 * 3 2 3 /4 2 2 3 3 2* 3 4 2/ 2 3

Solve As If Doing Mathematically – Order Of Operations

slide-22
SLIDE 22

22

Infix Prefix Postfix

3 * 2 + 3 – 4 / 2 / 2 - 3 +* 3 2 3 //4 2 2 3 3 2* 3+ 4 2/ 2/ 3 * 3 2 3 //4 2 2 3 3 2* 3 4 2/ 2/ 3

Solve As If Doing Mathematically – Order Of Operations

slide-23
SLIDE 23

23

Infix Prefix Postfix

3 * 2 + 3 – 4 / 2 / 2 - 3

  • +* 3 2 3 //4 2 2

3 3 2* 3+ 4 2/ 2/- 3 +* 3 2 3 //4 2 2 3 3 2* 3+ 4 2/ 2/ 3

Solve As If Doing Mathematically – Order Of Operations

slide-24
SLIDE 24

24

Infix Prefix Postfix

3 * 2 + 3 – 4 / 2 / 2 - 3

  • - +* 3 2 3 //4 2 2

3 3 2* 3+ 4 2/ 2/- 3 -

  • +* 3 2 3 //4 2 2

3 3 2* 3+ 4 2/ 2/- 3

Solve As If Doing Mathematically – Order Of Operations

slide-25
SLIDE 25

25

slide-26
SLIDE 26

( 3 + 2 ^ 3 ^ 2 / {4 * [ 5 – 4 ] * 1 } ) * 2

26

Infix Prefix Postfix

Solve As If Doing Mathematically – Order Of Operations

3 2 3 2 4 5 4 1 2 3 2 3 2 4 5 4 1 2 3 2 3 2 4 -5 4 1 2 3 2 3 2 4 5 4- 1 2

slide-27
SLIDE 27

( 3 + 2 ^ 3 ^ 2 / {4 * [ 5 – 4 ] * 1 } ) * 2

27

Infix Prefix Postfix

Solve As If Doing Mathematically – Order Of Operations

3 2 3 2 4

  • 5 4

1 2 3 2 3 2 4 5 4- 1 2 3 2 3 2 *4

  • 5 4

1 2 3 2 3 2 4 5 4-* 1 2

slide-28
SLIDE 28

( 3 + 2 ^ 3 ^ 2 / {4 * [ 5 – 4 ] * 1 } ) * 2

28

Infix Prefix Postfix

Solve As If Doing Mathematically – Order Of Operations

3 2 3 2 **4 -5 4 1 2 3 2 3 2 4 5 4-* 1* 2 3 2 3 2 *4 -5 4 1 2 3 2 3 2 4 5 4-* 1 2

slide-29
SLIDE 29

( 3 + 2 ^ 3 ^ 2 / {4 * [ 5 – 4 ] * 1 } ) * 2

29

Infix Prefix Postfix

Solve As If Doing Mathematically – Order Of Operations

3 2 3 2 **4 -5 4 1 2 3 2 3 2 4 5 4-* 1* 2 3 2 ^3 2 **4 -5 4 1 2 3 2 3 2^ 4 5 4-* 1* 2

slide-30
SLIDE 30

( 3 + 2 ^ 3 ^ 2 / {4 * [ 5 – 4 ] * 1 } ) * 2

30

Infix Prefix Postfix

Solve As If Doing Mathematically – Order Of Operations

3 2 ^3 2 **4 -5 4 1 2 3 2 3 2^ 4 5 4-* 1* 2 3 ^2 ^3 2 **4 -5 4 1 2 3 2 3 2^^ 4 5 4-* 1* 2

slide-31
SLIDE 31

( 3 + 2 ^ 3 ^ 2 / {4 * [ 5 – 4 ] * 1 } ) * 2

31

Infix Prefix Postfix

Solve As If Doing Mathematically – Order Of Operations

3 ^2 ^3 2 **4 -5 4 1 2 3 2 3 2^^ 4 5 4-* 1* 2 3 /^2 ^3 2 **4 -5 4 1 2 3 2 3 2^^ 4 5 4-* 1*/ 2

slide-32
SLIDE 32

( 3 + 2 ^ 3 ^ 2 / {4 * [ 5 – 4 ] * 1 } ) * 2

32

Infix Prefix Postfix

Solve As If Doing Mathematically – Order Of Operations

+3 /^2 ^3 2 **4 -5 4 1 2 3 2 3 2^^ 4 5 4-* 1*/+ 2 3 /^2 ^3 2 **4 -5 4 1 2 3 2 3 2^^ 4 5 4-* 1*/ 2

slide-33
SLIDE 33

( 3 + 2 ^ 3 ^ 2 / {4 * [ 5 – 4 ] * 1 } ) * 2

33

Infix Prefix Postfix

Solve As If Doing Mathematically – Order Of Operations

*+3 /^2 ^3 2 **4 -5 4 1 2 3 2 3 2^^ 4 5 4-* 1*/+ 2* +3 /^2 ^3 2 **4 -5 4 1 2 3 2 3 2^^ 4 5 4-* 1*/+ 2

slide-34
SLIDE 34

34

Now that we can manually create the postfix expressions, how do we do this with a computer program?

Info

Max Top

  • 1

5

1 2 3 4 5

slide-35
SLIDE 35

35

slide-36
SLIDE 36

36

slide-37
SLIDE 37

37

slide-38
SLIDE 38

38

Info

Max Top

  • 1

5

1 2 3 4 5

( 2 + 3 ) * ( 5 – 2 )

( ICP = 7  Always PUSH opener to stack) ( ISP of Empty Stack = -1)

Stack <char> Postfix(5); To Form Postfix

  • Examine one Infix character at a time – left to right
  • If Operand, Write it to the Postfix String
  • If Scope Opener or Operator
  • If the In-Coming Priority (ICP) is greater than the In-Stack

Priority (ISP) Push

  • If ICP < ISP Pop – Write Values To Postfix Until Can Push
  • If Scope Closer, Pop till find opener – Write values to

Postfix – Throw out scope opener!

  • Empty Stack – Write Values To Postfix

2 3 + 5 2 - *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-39
SLIDE 39

39

Info

Max Top 5

1 2 3 4 5

(

( 2 + 3 ) * ( 5 – 2 )

Write Operand To Postfix String ( ISP = That Of Top Char = 0 Postfix = 2

To Form Postfix

  • Examine one Infix character at a time – left to right
  • If Operand, Write it to the Postfix String
  • If Scope Opener or Operator
  • If the In-Coming Priority (ICP) is greater than the In-Stack

Priority (ISP) Push

  • If ICP < ISP Pop – Write Values To Postfix Until Can Push
  • If Scope Closer, Pop till find opener – Write values to

Postfix – Throw out scope opener!

  • Empty Stack – Write Values To Postfix

2 3 + 5 2 - *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-40
SLIDE 40

40

Info

Max Top 5

1 2 3 4 5

(

( 2 + 3 ) * ( 5 – 2 )

ICP = 1 > ISP = 0  Push Operator ( ISP = That Of Top Char = 0 Postfix = 2

To Form Postfix

  • Examine one Infix character at a time – left to right
  • If Operand, Write it to the Postfix String
  • If Scope Opener or Operator
  • If the In-Coming Priority (ICP) is greater than the In-Stack

Priority (ISP) Push

  • If ICP < ISP Pop – Write Values To Postfix Until Can Push
  • If Scope Closer, Pop till find opener – Write values to

Postfix – Throw out scope opener!

  • Empty Stack – Write Values To Postfix

2 3 + 5 2 - *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-41
SLIDE 41

41

Info

Max Top 1 5

1 2 3 4 5

( +

( 2 + 3 ) * ( 5 – 2 )

( ISP = That Of Top Char = 2 Postfix = 2 Write Operand To Postfix String 3

To Form Postfix

  • Examine one Infix character at a time – left to right
  • If Operand, Write it to the Postfix String
  • If Scope Opener or Operator
  • If the In-Coming Priority (ICP) is greater than the In-Stack

Priority (ISP) Push

  • If ICP < ISP Pop – Write Values To Postfix Until Can Push
  • If Scope Closer, Pop till find opener – Write values to

Postfix – Throw out scope opener!

  • Empty Stack – Write Values To Postfix

2 3 + 5 2 - *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-42
SLIDE 42

42

Info

Max Top 1 5

1 2 3 4 5

( +

( 2 + 3 ) * ( 5 – 2 )

( ISP = That Of Top Char = 2 Postfix = 2 3 Scope Closer – Pop & Add To Postfix +

To Form Postfix

  • Examine one Infix character at a time – left to right
  • If Operand, Write it to the Postfix String
  • If Scope Opener or Operator
  • If the In-Coming Priority (ICP) is greater than the In-Stack

Priority (ISP) Push

  • If ICP < ISP Pop – Write Values To Postfix Until Can Push
  • If Scope Closer, Pop till find opener – Write values to

Postfix – Throw out scope opener!

  • Empty Stack – Write Values To Postfix

2 3 + 5 2 - *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-43
SLIDE 43

43

Info

Max Top

  • 1

5

1 2 3 4 5

( 2 + 3 ) * ( 5 – 2 )

( ISP -1 Postfix = 2 3 + ICP = 3 > ISP = -1  Push

To Form Postfix

  • Examine one Infix character at a time – left to right
  • If Operand, Write it to the Postfix String
  • If Scope Opener or Operator
  • If the In-Coming Priority (ICP) is greater than the In-Stack

Priority (ISP) Push

  • If ICP < ISP Pop – Write Values To Postfix Until Can Push
  • If Scope Closer, Pop till find opener – Write values to

Postfix – Throw out scope opener!

  • Empty Stack – Write Values To Postfix

2 3 + 5 2 - *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-44
SLIDE 44

44

Info

Max Top 5

1 2 3 4 5

*

( 2 + 3 ) * ( 5 – 2 )

( ISP 4 Postfix = 2 3 + ( ICP = 7  Always PUSH opener to stack)

To Form Postfix

  • Examine one Infix character at a time – left to right
  • If Operand, Write it to the Postfix String
  • If Scope Opener or Operator
  • If the In-Coming Priority (ICP) is greater than the In-Stack

Priority (ISP) Push

  • If ICP < ISP Pop – Write Values To Postfix Until Can Push
  • If Scope Closer, Pop till find opener – Write values to

Postfix – Throw out scope opener!

  • Empty Stack – Write Values To Postfix

2 3 + 5 2 - *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-45
SLIDE 45

45

Info

Max Top 1 5

1 2 3 4 5

* (

( 2 + 3 ) * ( 5 – 2 )

( ISP 0 Postfix = 2 3 + Write Operand To Postfix String 5

To Form Postfix

  • Examine one Infix character at a time – left to right
  • If Operand, Write it to the Postfix String
  • If Scope Opener or Operator
  • If the In-Coming Priority (ICP) is greater than the In-Stack

Priority (ISP) Push

  • If ICP < ISP Pop – Write Values To Postfix Until Can Push
  • If Scope Closer, Pop till find opener – Write values to

Postfix – Throw out scope opener!

  • Empty Stack – Write Values To Postfix

2 3 + 5 2 - *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-46
SLIDE 46

46

Info

Max Top 1 5

1 2 3 4 5

* (

( 2 + 3 ) * ( 5 – 2 )

( ISP 0 Postfix = 2 3 + 5 ICP = 1 > ISP = 0  Push

To Form Postfix

  • Examine one Infix character at a time – left to right
  • If Operand, Write it to the Postfix String
  • If Scope Opener or Operator
  • If the In-Coming Priority (ICP) is greater than the In-Stack

Priority (ISP) Push

  • If ICP < ISP Pop – Write Values To Postfix Until Can Push
  • If Scope Closer, Pop till find opener – Write values to

Postfix – Throw out scope opener!

  • Empty Stack – Write Values To Postfix

2 3 + 5 2 - *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-47
SLIDE 47

47

Info

Max Top 2 5

1 2 3 4 5

* (

  • ( 2 + 3 ) * ( 5 – 2 )

( ISP 1 Postfix = 2 3 + 5 Write Operand To Postfix String 2

To Form Postfix

  • Examine one Infix character at a time – left to right
  • If Operand, Write it to the Postfix String
  • If Scope Opener or Operator
  • If the In-Coming Priority (ICP) is greater than the In-Stack

Priority (ISP) Push

  • If ICP < ISP Pop – Write Values To Postfix Until Can Push
  • If Scope Closer, Pop till find opener – Write values to

Postfix – Throw out scope opener!

  • Empty Stack – Write Values To Postfix

2 3 + 5 2 - *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-48
SLIDE 48

48

Info

Max Top 2 5

1 2 3 4 5

* (

  • ( 2 + 3 ) * ( 5 – 2 )

( ISP 1 Postfix = 2 3 + 5 2 Scope Closer – Pop & Add To Postfix

  • To Form Postfix
  • Examine one Infix character at a time – left to right
  • If Operand, Write it to the Postfix String
  • If Scope Opener or Operator
  • If the In-Coming Priority (ICP) is greater than the In-Stack

Priority (ISP) Push

  • If ICP < ISP Pop – Write Values To Postfix Until Can Push
  • If Scope Closer, Pop till find opener – Write values to

Postfix – Throw out scope opener!

  • Empty Stack – Write Values To Postfix

2 3 + 5 2 - *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-49
SLIDE 49

49

Info

Max Top 5

1 2 3 4 5

*

( 2 + 3 ) * ( 5 – 2 )

( ISP 2 Postfix = 2 3 + 5 2 - Done – Pop Stack & Add To Postfix *

To Form Postfix

  • Examine one Infix character at a time – left to right
  • If Operand, Write it to the Postfix String
  • If Scope Opener or Operator
  • If the In-Coming Priority (ICP) is greater than the In-Stack

Priority (ISP) Push

  • If ICP < ISP Pop – Write Values To Postfix Until Can Push
  • If Scope Closer, Pop till find opener – Write values to

Postfix – Throw out scope opener!

  • Empty Stack – Write Values To Postfix

2 3 + 5 2 - *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-50
SLIDE 50

50

Info

Max Top

  • 1

5

1 2 3 4 5

( 2 + 3 ) * ( 5 – 2 )

( ISP 2 Postfix = 2 3 + 5 2 - *

To Form Postfix

  • Examine one Infix character at a time – left to right
  • If Operand, Write it to the Postfix String
  • If Scope Opener or Operator
  • If the In-Coming Priority (ICP) is greater than the In-Stack

Priority (ISP) Push

  • If ICP < ISP Pop – Write Values To Postfix Until Can Push
  • If Scope Closer, Pop till find opener – Write values to

Postfix – Throw out scope opener!

  • Empty Stack – Write Values To Postfix

2 3 + 5 2 - *

It is finished – Success! – Stack Is Empty!

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-51
SLIDE 51

51

slide-52
SLIDE 52

52

Info

Max Top

  • 1

5

1 2 3 4 5

Infix = 5 + 2 ^ 3 ^ 2

ISP = -1

5 2 3 2 ^ ^ +

Postfix =

Write Operand To Postfix String 5

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-53
SLIDE 53

53

Info

Max Top

  • 1

5

1 2 3 4 5

Infix = 5 + 2 ^ 3 ^ 2

ISP = -1

5 2 3 2 ^ ^ +

Postfix = 5

ICP = 1 > ISP -1  PUSH

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-54
SLIDE 54

54

Info

Max Top 5

1 2 3 4 5

+ Infix = 5 + 2 ^ 3 ^ 2

ISP = 1

5 2 3 2 ^ ^ +

Postfix = 5

Write Operand To Postfix String 2

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-55
SLIDE 55

55

Info

Max Top 5

1 2 3 4 5

+ Infix = 5 + 2 ^ 3 ^ 2

ISP = 2

5 2 3 2 ^ ^ +

Postfix = 5 2

ICP = 6 > ISP 2  PUSH

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-56
SLIDE 56

56

Info

Max Top 1 5

1 2 3 4 5

+ ^ Infix = 5 + 2 ^ 3 ^ 2

ISP = 5

5 2 3 2 ^ ^ +

Postfix = 5 2

Write Operand To Postfix String 3

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-57
SLIDE 57

57

Info

Max Top 1 5

1 2 3 4 5

+ ^ Infix = 5 + 2 ^ 3 ^ 2

ISP = 5

5 2 3 2 ^ ^ +

Postfix = 5 2 3

ICP = 6 > ISP 5  Push

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-58
SLIDE 58

58

Info

Max Top 2 5

1 2 3 4 5

+ ^ ^ Infix = 5 + 2 ^ 3 ^ 2

ISP = 5

5 2 3 2 ^ ^ +

Postfix = 5 2 3

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

Write Operand To Postfix String 2

slide-59
SLIDE 59

59

Info

Max Top 2 5

1 2 3 4 5

+ ^ ^ Infix = 5 + 2 ^ 3 ^ 2

ISP = 5

5 2 3 2 ^ ^ +

Postfix = 5 2 3 2

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

^ ^ + Done – Pop Stack & Add To Postfix

slide-60
SLIDE 60

60

slide-61
SLIDE 61

61

Info

Max Top

  • 1

5

1 2 3 4 5

Infix = 3 * 2 + 3 – 4 / 2 / 2 – 3 ISP = -1

3 2 * 3 + 4 2 / 2 / - 3 -

Postfix =

Write Operand To Postfix String 3

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

slide-62
SLIDE 62

62

Info

Max Top

  • 1

5

1 2 3 4 5

Infix = 3 * 2 + 3 – 4 / 2 / 2 - 3 ISP = -1

Postfix = 3

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

ICP = 3 > ISP = -1  Push *

3 2 * 3 + 4 2 / 2 / - 3 -

slide-63
SLIDE 63

63

Info

Max Top

  • 1

5

1 2 3 4 5

*

Infix = 3 * 2 + 3 – 4 / 2 / 2 - 3 ISP = 4

Postfix = 3

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

Write Operand To Postfix String 2

3 2 * 3 + 4 2 / 2 / - 3 -

slide-64
SLIDE 64

64

Info

Max Top

  • 1

5

1 2 3 4 5

*

Infix = 3 * 2 + 3 – 4 / 2 / 2 - 3 ISP = 4

Postfix = 3 2

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

ICP = 1 < ISP = 4  Pop * Add To Postfix & Try Again! Push + *

3 2 * 3 + 4 2 / 2 / - 3 -

slide-65
SLIDE 65

65

Info

Max Top

  • 1

5

1 2 3 4 5

+

Infix = 3 * 2 + 3 – 4 / 2 / 2 - 3 ISP = 2

Postfix = 3 2 *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

3 Write Operand To Postfix String

3 2 * 3 + 4 2 / 2 / - 3 -

slide-66
SLIDE 66

66

Info

Max Top

  • 1

5

1 2 3 4 5

+

Infix = 3 * 2 + 3 – 4 / 2 / 2 - 3 ISP = 2

Postfix = 3 2 * 3

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

+ ICP = 1 < ISP = 2  Pop + Add To Postfix & Try Again! Push -

3 2 * 3 + 4 2 / 2 / - 3 -

slide-67
SLIDE 67

67

Info

Max Top

  • 1

5

1 2 3 4 5

  • Infix = 3 * 2 + 3 – 4 / 2 / 2 - 3

ISP = 2

Postfix = 3 2 * 3 +

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

4 Write Operand To Postfix String

3 2 * 3 + 4 2 / 2 / - 3 -

slide-68
SLIDE 68

68

Info

Max Top

  • 1

5

1 2 3 4 5

  • Infix = 3 * 2 + 3 – 4 / 2 / 2 - 3

ISP = 2

Postfix = 3 2 * 3 + 4

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

ICP = 3 > ISP = 2  Push /

3 2 * 3 + 4 2 / 2 / - 3 -

slide-69
SLIDE 69

69

Info

Max Top 5

1 2 3 4 5

  • /

Infix = 3 * 2 + 3 – 4 / 2 / 2 - 3 ISP = 2

Postfix = 3 2 * 3 + 4

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

2

3 2 * 3 + 4 2 / 2 / - 3 -

Write Operand To Postfix String

slide-70
SLIDE 70

70

Info

Max Top 1 5

1 2 3 4 5

  • /

Infix = 3 * 2 + 3 – 4 / 2 / 2 - 3 ISP = 4

Postfix = 3 2 * 3 + 4 2

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

/

3 2 * 3 + 4 2 / 2 / - 3 -

ICP = 3 < ISP = 4  Pop / Add To Postfix & Try Again! Push /

slide-71
SLIDE 71

71

Info

Max Top 1 5

1 2 3 4 5

  • /

Infix = 3 * 2 + 3 – 4 / 2 / 2 - 3 ISP = 4

Postfix = 3 2 * 3 + 4 2 /

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

2

3 2 * 3 + 4 2 / 2 / - 3 -

Write Operand To Postfix String

slide-72
SLIDE 72

72

Info

Max Top 1 5

1 2 3 4 5

  • /

Infix = 3 * 2 + 3 – 4 / 2 / 2 - 3 ISP = 4

Postfix = 3 2 * 3 + 4 2 / 2

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

/

3 2 * 3 + 4 2 / 2 / - 3 -

ICP = 1 < ISP = 4  Pop / Add To Postfix & Try Again! Pop  Add To Postfix & Try Again! Push -

slide-73
SLIDE 73

73

Info

Max Top 5

1 2 3 4 5

  • Infix = 3 * 2 + 3 – 4 / 2 / 2 - 3

ISP = 2

Postfix = 3 2 * 3 + 4 2 / 2 / -

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

3

3 2 * 3 + 4 2 / 2 / - 3 -

Write Operand To Postfix String

slide-74
SLIDE 74

74

Info

Max Top 5

1 2 3 4 5

  • Infix = 3 * 2 + 3 – 4 / 2 / 2 - 3

ISP = 2

Postfix = 3 2 * 3 + 4 2 / 2 / - 3

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

  • 3 2 * 3 + 4 2 / 2 / - 3 -

Done  Pop Stack & Add To Postfix

slide-75
SLIDE 75

75

slide-76
SLIDE 76

76

Info

Max Top

  • 1

5

1 2 3 4 5

ISP = -1

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix =

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

( ICP = 7  Always PUSH opener to stack)

3 2 3 2^ ^ 4 5 4 - * 1* / + 2 *

slide-77
SLIDE 77

77

Info

Max Top 5

1 2 3 4 5

( ISP = 0

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix =

3

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

Write Operand To Postfix String

slide-78
SLIDE 78

78

Info

Max Top 5

1 2 3 4 5

( ISP = 0

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix =

3

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

ICP = 1 > ISP = 0  Push +

slide-79
SLIDE 79

79

Info

Max Top 1 5

1 2 3 4 5

(

+

ISP = 2

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

2 Write Operand To Postfix String

slide-80
SLIDE 80

80

Info

Max Top 1 5

1 2 3 4 5

(

+

ISP = 2

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

ICP = 6 > ISP = 2  Push ^

slide-81
SLIDE 81

81

Info

Max Top 2 5

1 2 3 4 5

(

+ ^

ISP = 5

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

Write Operand To Postfix String 3

slide-82
SLIDE 82

82

Info

Max Top 2 5

1 2 3 4 5

(

+ ^

ISP = 5

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

ICP = 6 > ISP = 5  Push ^

slide-83
SLIDE 83

83

Info

Max Top 2 5

1 2 3 4 5

(

+ ^

ISP = 5

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

2 Write Operand To Postfix String

^

slide-84
SLIDE 84

84

Info

Max Top 3 5

1 2 3 4 5

(

+ ^

ISP = 5

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

^

^

ICP = 3 < ISP = 5  Pop ^Add To Postfix & Try Again! Pop ^Add To Postfix & Try Again! Push / ^

slide-85
SLIDE 85

85

Info

Max Top 2 5

1 2 3 4 5

(

+ /

ISP = 4

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

(ICP = 7 > ISP = 4  Push Always PUSH opener to stack

slide-86
SLIDE 86

86

Info

Max Top 3 5

1 2 3 4 5

(

+ /

ISP = 0

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

4

{

Write Operand To Postfix String

slide-87
SLIDE 87

87

Info

Max Top 3 5

1 2 3 4 5

(

+ /

ISP = 0

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^ 4

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

{

ICP = 3 > ISP = 0  Push *

slide-88
SLIDE 88

88

Info

Max Top 4 5

1 2 3 4 5

(

+ /

ISP = 4

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^ 4

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

{ *

(ICP = 7 > ISP = 4  Push Always PUSH opener to stack

slide-89
SLIDE 89

89

Info

Max Top 5 5

1 2 3 4 5

(

+ / [

ISP = 0

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^ 4

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

{ *

5 Write Operand To Postfix String

slide-90
SLIDE 90

90

Info

Max Top 5 5

1 2 3 4 5

(

+ / [

ISP = 0

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^ 4 5

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

{ *

(ICP = 1 > ISP = 0  Push Always PUSH opener to stack

slide-91
SLIDE 91

91

Info

Top 5

1 2 3 4 5

(

+ / [

ISP = 1

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^ 4 5

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

{ *

4

6

  • Write Operand To Postfix String
slide-92
SLIDE 92

92

Info

Top 5

1 2 3 4 5

(

+ / [

ISP = 1

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^ 4 5 4

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

{ *

  • 6
  • Pop Stack Till Find Matching

Opener  Add - To Postfix

slide-93
SLIDE 93

93

Info

Top 4

1 2 3 4 5

(

+ /

ISP = 4

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^ 4 5 4 -

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

{ *

6

(ICP = 1 > ISP = 4  Pop *Add To Postfix & Try Again! Push - *

slide-94
SLIDE 94

94

Info

Top 4

1 2 3 4 5

(

+ /

ISP = 2

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^ 4 5 4 - *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

{ *

6

1 Write Operand To Postfix String

slide-95
SLIDE 95

95

Info

Top 4

1 2 3 4 5

(

+ /

ISP = 2

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^ 4 5 4 - * 1

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

{ *

6

* Pop Stack Till Find Matching Opener  Add - To Postfix

slide-96
SLIDE 96

96

Info

Top 2

1 2 3 4 5

(

+ /

ISP = 4

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^ 4 5 4 - * 1 *

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

6

/ Pop Stack Till Find Matching Opener  Add - To Postfix +

slide-97
SLIDE 97

97

Info

Top

  • 1

1 2 3 4 5

ISP = -1

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^ 4 5 4 - * 1 * / +

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

6

(ICP = 3 > ISP = -1  Push *

slide-98
SLIDE 98

98

Info

Top

1 2 3 4 5

* ISP = 4

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^ 4 5 4 - * 1 * / +

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

6

Write Operand To Postfix String 2

slide-99
SLIDE 99

99

Info

Top

1 2 3 4 5

* ISP = 4

3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2 *

Postfix = 3 2 3 2 ^ ^ 4 5 4 - * 1 * / + 2

ICP ISP

+ - * / ^ ({[ )}]

1 3 6 7

  • 5

4 2

( 3 + 2 ^ 3 ^ 2 / { 4 * [ 5 – 4 ] * 1 } ) * 2

6

* Done  Pop Stack & Add To Postfix

slide-100
SLIDE 100

Scala: var st = new charStack(50) Stack <char> Postfix(5); What type of stack was to create the Postfix from the Infix?

100

slide-101
SLIDE 101

You Must Have Function def createPostfix (infix : String) : String = { // You Do "2 3 +" }

Test With Multiple Digit Doubles You May Assume A Blank Between Each Token In The Infix Expression You May Assume That The Infix Is Valid (Other Than ({[)

101

slide-102
SLIDE 102

if ((diagnosticLevel == 20) || (diagnosticLevel == 99)) { var postfix = "?" var infix = "?" do { println("\n\n\n====================================================") println("===== Interactive Testing createPostfix =====") println("===== diagnosticLevel = 20 =====") println("====================================================\n") println print("\nEnter Infix <QUIT to Exit> : ") infix = readLine if (postfix.toUpperCase != "QUIT") { println ("\nInfix Expression = " + infix + "\n") var postfix = createPostfix(infix) println("\n===> Postfix Solution = " + postfix) } } while (infix.toUpperCase != "QUIT")

102

Add Your Own Diagnostic Testing You Must Include The Following  Make Any Corrections Necessary! Set Your Diagnostic