• No results found

Data Structures and Algorithms V Otávio Braga

N/A
N/A
Protected

Academic year: 2021

Share "Data Structures and Algorithms V Otávio Braga"

Copied!
72
0
0

Loading.... (view fulltext now)

Full text

(1)

Data Structures and Algorithms

V22.0102

(2)

Infix to Postfix Conversion

• We use a stack

• When an operand is read, output it • When an operator is read

– Pop until the top of the stack has an element of lower precedence

– Then push it

• When ) is found, pop until we find the matching ( • ( has the lowest precedence when in the stack

• but has the highest precedence when in the input

• When we reach the end of input, pop until the stack is empty

(3)

Infix to Postfix Conversion

Example 1

(4)

Infix to Postfix Conversion

Example 1

• 3+4*5/6 • Stack: • Output:

(5)

Infix to Postfix Conversion

Example 1

• 3+4*5/6 • Stack:

(6)

Infix to Postfix Conversion

Example 1

• 3+4*5/6 • Stack: + • Output: 3

(7)

Infix to Postfix Conversion

Example 1

• 3+4*5/6 • Stack: +

(8)

Infix to Postfix Conversion

Example 1

• 3+4*5/6 • Stack: + * • Output: 3 4

(9)

Infix to Postfix Conversion

Example 1

• 3+4*5/6 • Stack: + *

(10)

Infix to Postfix Conversion

Example 1

• 3+4*5/6 • Stack: +

(11)

Infix to Postfix Conversion

Example 1

• 3+4*5/6 • Stack: + /

(12)

Infix to Postfix Conversion

Example 1

• 3+4*5/6 • Stack: + /

(13)

Infix to Postfix Conversion

Example 1

• 3+4*5/6 • Stack: +

(14)

Infix to Postfix Conversion

Example 1

• 3+4*5/6 • Stack: • Output: 3 4 5 * 6 / + • Done!
(15)

Infix to Postfix Conversion

Example 2

(16)

Infix to Postfix Conversion

Example 2

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

(17)

Infix to Postfix Conversion

Example 2

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

(18)

Infix to Postfix Conversion

Example 2

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

(19)

Infix to Postfix Conversion

Example 2

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

(20)

Infix to Postfix Conversion

Example 2

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

(21)

Infix to Postfix Conversion

Example 2

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

(22)

Infix to Postfix Conversion

Example 2

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

(23)

Infix to Postfix Conversion

Example 2

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

(24)

Infix to Postfix Conversion

Example 2

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

(25)

Infix to Postfix Conversion

Example 2

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

(26)

Infix to Postfix Conversion

Example 2

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

(27)

Infix to Postfix Conversion

Example 2

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

(28)

Infix to Postfix Conversion

Example 2

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

(29)

-Infix to Postfix Conversion

Example 2

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

(30)

-Infix to Postfix Conversion

Example 2

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

(31)

Infix to Postfix Conversion

Example 2

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

(32)

Infix to Postfix Conversion

Example 2

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

(33)

Infix to Postfix Conversion

Example 2

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

(34)

Infix to Postfix Conversion

Example 2

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

(35)

Infix to Postfix Conversion

Example 2

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

(36)

Infix to Postfix Conversion

Example 2

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

(37)

Infix to Postfix Conversion

Example 2

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

(38)

Infix to Postfix Conversion

Example 2

• (300+23)*(43-21)/(84+7) • Stack: • Output: 300 23 + 43 21 - * 84 7 + / • Done!
(39)

Infix to Postfix Conversion

Example 3

(40)

Infix to Postfix Conversion

Example 3

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

(41)

Infix to Postfix Conversion

Example 3

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

(42)

Infix to Postfix Conversion

Example 3

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

(43)

Infix to Postfix Conversion

Example 3

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

(44)

Infix to Postfix Conversion

Example 3

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

(45)

Infix to Postfix Conversion

Example 3

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

(46)

Infix to Postfix Conversion

Example 3

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

(47)

Infix to Postfix Conversion

Example 3

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

(48)

Infix to Postfix Conversion

Example 3

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

(49)

Infix to Postfix Conversion

Example 3

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

(50)

Infix to Postfix Conversion

Example 3

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

(51)

Infix to Postfix Conversion

Example 3

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

(52)

Infix to Postfix Conversion

Example 3

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

(53)

-Infix to Postfix Conversion

Example 3

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

(54)

-Infix to Postfix Conversion

Example 3

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

(55)

Infix to Postfix Conversion

Example 3

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

(56)

Infix to Postfix Conversion

Example 3

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

(57)

Infix to Postfix Conversion

Example 3

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

(58)

Infix to Postfix Conversion

Example 3

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

(59)

Infix to Postfix Conversion

Example 3

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

(60)

Infix to Postfix Conversion

Example 3

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

(61)

Infix to Postfix Conversion

Example 3

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

(62)

-Infix to Postfix Conversion

Example 3

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

(63)

-Infix to Postfix Conversion

Example 3

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

(64)

-Infix to Postfix Conversion

Example 3

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

(65)

-Infix to Postfix Conversion

Example 3

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

(66)

Infix to Postfix Conversion

Example 3

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

(67)

Infix to Postfix Conversion

Example 3

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

(68)

Infix to Postfix Conversion

Example 3

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

(69)

Infix to Postfix Conversion

Example 3

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

(70)

Infix to Postfix Conversion

Example 3

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

(71)

Infix to Postfix Conversion

Example 3

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

(72)

Infix to Postfix Conversion

Example 3

• (4+8)*(6-5)/((3-2)*(2+2)) • Stack: • Output: 4 8 + 6 5 - * 3 2 – 2 2 + * / • Done!

References

Related documents

Indiana argued that either the court or a jury must determine which cause was the ‘efficient’ or dominant cause and then determine coverage with reference to that cause alone

Blanks can convert infix expression commonly used to on your example consider association is converted into prefix to postfix converter converts infix to represent integers in.. We

i) We show that we can push BitTorrent locality much further than what was previously proposed, which enables to reduce by several orders of magnitude the inter-ISP traffic and to

It is a joint venture between Infocredit Holdings Pte Ltd, an established provider of worldwide business information and the first in Singapore in 1997 to be awarded the ISO

Hypothesis 2(a): A self-directed career attitude (SDA) moderates the relationship between the knowledge characteristics of (i) skill variety and (ii) skill specialization and

He maintains a project diary and exploits specialist knowledge in the specification development to create and maintain standard and complex documents of the project or content

MAIN BEARINGS JOURNAL SEAL TO CYLINDER BLOCK FLYWHEEL AND RING GEAR CRANKSHAFT SPROCKET -SEAL RETAINER BOLT LOCKWASHER. CAP TO

HRW zone 2 is characterised by negative component scores on axis 1 related to low abundances of diatom valves and the presence of consolidated sea-ice cover over the