72

Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
โครงสร้างข้อมูลและอัลกอริทึม ตัวอย่างการประยุกต์ใช้ โครงสร้างข้อมูลสแต็กในการแปลง Infix to Postfix
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
Page 2: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix Conversion

acer
Typewritten Text
Algorithm
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
1. เมื่อพบเครื่องหมายคำนวณทางคณิตศาสตร์ให้อ่านและแสดงผลข้อมูลออก ตัวเลขก่อนหน้านี้ออกมาแล้วนำเครื่องหมายทางคณิตศาสตร์ไปเก็บไว้ในสแตก 2. หากพบว่าลำดับความสำคัญของเครื่องหมายทางคณิตศาสตร์น้อยกว่าจะทำการนำ เครื่องหมายทางคณิตศาสตร์ที่มีลำดับความสำคัญมากกว่าที่อยู่ในแต่สแตกออกมา แสดงผลแล้วนำเครื่องหมายทางคณิตศาสตร์ที่มีลำดับความสำคัญน้อยกว่าไปเก็บ ไว้ในสแตก 3. ถ้าข้อมูลที่อ่านหมดแล้วให้นำเครื่องหมายที่อยู่ในสแตกออกมาแสดงผล 4. เมื่อพบเครื่องหมาย ( ให้นำข้อมูลตัวถัดไปออกมาแสดงผล 5. เมื่อพบเครื่องหมาย ) ให้นำข้อมูลที่อยู่ในสแตกออกมาแสดงผลจนพบเครื่องหมาย ( แล้วพบทิ้งทั้งหมด
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
acer
Typewritten Text
Page 3: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 1

• 3+4*5/6

Page 4: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 1

• 3+4*5/6

• Stack:

• Output:

acer
Typewritten Text
Page 5: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 1

• 3+4*5/6

• Stack:

• Output: 3

Page 6: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 1

• 3+4*5/6

• Stack: +

• Output: 3

Page 7: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 1

• 3+4*5/6

• Stack: +

• Output: 3 4

Page 8: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 1

• 3+4*5/6

• Stack: + *

• Output: 3 4

Page 9: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 1

• 3+4*5/6

• Stack: + *

• Output: 3 4 5

acer
Typewritten Text
Page 10: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 1

• 3+4*5/6

• Stack: +

• Output: 3 4 5 *

Page 11: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 1

• 3+4*5/6

• Stack: + /

• Output: 3 4 5 *

Page 12: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 1

• 3+4*5/6

• Stack: + /

• Output: 3 4 5 * 6

Page 13: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 1

• 3+4*5/6

• Stack: +

• Output: 3 4 5 * 6 /

Page 14: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 1

• 3+4*5/6

• Stack:

• Output: 3 4 5 * 6 / +

• Done!

Page 15: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

Page 16: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack:

• Output:

Page 17: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: (

• Output:

Page 18: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: (

• Output: 300

Page 19: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: ( +

• Output: 300

Page 20: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: ( +

• Output: 300 23

Page 21: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: (

• Output: 300 23 +

Page 22: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack:

• Output: 300 23 +

Page 23: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: *

• Output: 300 23 +

Page 24: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: * (

• Output: 300 23 +

Page 25: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: * (

• Output: 300 23 + 43

Page 26: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: * ( -

• Output: 300 23 + 43

Page 27: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: * ( -

• Output: 300 23 + 43 21

Page 28: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: * (

• Output: 300 23 + 43 21 -

Page 29: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: *

• Output: 300 23 + 43 21 -

Page 30: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack:

• Output: 300 23 + 43 21 - *

Page 31: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: /

• Output: 300 23 + 43 21 - *

Page 32: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: / (

• Output: 300 23 + 43 21 - *

Page 33: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: / (

• Output: 300 23 + 43 21 - * 84

Page 34: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: / ( +

• Output: 300 23 + 43 21 - * 84

Page 35: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: / ( +

• Output: 300 23 + 43 21 - * 84 7

Page 36: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: / (

• Output: 300 23 + 43 21 - * 84 7 +

Page 37: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack: /

• Output: 300 23 + 43 21 - * 84 7 +

Page 38: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 2

• (300+23)*(43-21)/(84+7)

• Stack:

• Output: 300 23 + 43 21 - * 84 7 + /

• Done!

Page 39: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

Page 40: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack:

• Output:

Page 41: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: (

• Output:

Page 42: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: (

• Output: 4

Page 43: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: ( +

• Output: 4

Page 44: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: ( +

• Output: 4 8

Page 45: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: (

• Output: 4 8 +

Page 46: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack:

• Output: 4 8 +

Page 47: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: *

• Output: 4 8 +

Page 48: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: * (

• Output: 4 8 +

Page 49: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: * (

• Output: 4 8 + 6

Page 50: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: * ( -

• Output: 4 8 + 6

Page 51: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: * ( -

• Output: 4 8 + 6 5

Page 52: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: * (

• Output: 4 8 + 6 5 -

Page 53: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: *

• Output: 4 8 + 6 5 -

Page 54: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack:

• Output: 4 8 + 6 5 - *

Page 55: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: /

• Output: 4 8 + 6 5 - *

Page 56: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / (

• Output: 4 8 + 6 5 - *

Page 57: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / ( (

• Output: 4 8 + 6 5 - *

Page 58: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / ( (

• Output: 4 8 + 6 5 - * 3

Page 59: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / ( ( -

• Output: 4 8 + 6 5 - * 3

Page 60: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / ( ( -

• Output: 4 8 + 6 5 - * 3 2

Page 61: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / ( (

• Output: 4 8 + 6 5 - * 3 2 -

Page 62: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / (

• Output: 4 8 + 6 5 - * 3 2 -

Page 63: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / ( *

• Output: 4 8 + 6 5 - * 3 2 -

Page 64: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / ( * (

• Output: 4 8 + 6 5 - * 3 2 -

Page 65: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / ( * (

• Output: 4 8 + 6 5 - * 3 2 - 2

Page 66: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / ( * ( +

• Output: 4 8 + 6 5 - * 3 2 - 2

Page 67: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / ( * ( +

• Output: 4 8 + 6 5 - * 3 2 – 2 2

Page 68: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / ( * (

• Output: 4 8 + 6 5 - * 3 2 – 2 2 +

Page 69: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / ( *

• Output: 4 8 + 6 5 - * 3 2 – 2 2 +

Page 70: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: / (

• Output: 4 8 + 6 5 - * 3 2 – 2 2 + *

Page 71: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack: /

• Output: 4 8 + 6 5 - * 3 2 – 2 2 + *

Page 72: Data Structures and Algorithms InfixToPostfix.pdf · 2018-01-19 · Infix to Postfix Conversion. Algorithm. 1. เมื่อพบเครื่องหมายคำนวณทางคณิต⠎㈎⨎ᔎ⌎䰎䌎⬎䤎

Infix to Postfix ConversionExample 3

• (4+8)*(6-5)/((3-2)*(2+2))

• Stack:

• Output: 4 8 + 6 5 - * 3 2 – 2 2 + * /

• Done!