1 / 10

# Lab Session 5 - PowerPoint PPT Presentation

COP 3502 Spring 2005 Christopher Elwell. Lab Session 5. Administrivia. Recitation notes duplicated online: http://www.cs.ucf.edu/~celwell Office Hours MTWF 2-4 PM Quizzes and Tests Quizzes may be given at any time (lab or class) Assignment 1 Should have been submitted

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'Lab Session 5' - saniya

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Christopher Elwell

Lab Session 5

• Recitation notes duplicated online:

• http://www.cs.ucf.edu/~celwell

• Office Hours

• MTWF 2-4 PM

• Quizzes and Tests

• Quizzes may be given at any time (lab or class)

• Assignment 1

• Should have been submitted

• Cutoff date (with penalty) 2/10/05

• Solve using a stack

• When you encounter a number, push it onto the stack

• When you encounter an operator (*, /, +, -)

• Pop two numbers from the stack

• Perform the operation

• Push the result onto the stack

1.) 6 7 9 + -

2.) 6 7 9 + - 2 / 11 2 2 / + *

3.) 2 8 – 12 * 2 5 6 + - / 3 3 / *

4.) 4 4 4 4 + - * 2 4 + + 5 / 3 *

1.) 6 7 9 + - = -10

2.) 6 7 9 + - 2 / 11 2 2 / + * = -60

3.) 2 8 – 12 * 2 5 6 + - / 3 3 / * = 8

4.) 4 4 4 4 + - * 2 4 + + 5 / 3 * = -6

• General Algorithm:

• Process from left to right

• Copy numbers directly to the output

• Use stack for operators

• Always push ( onto the stack

• When you encounter ), pop symbols off the stack until you reach the preceding ( (discard both parentheses)

• Operators:

• If the operator being “scanned” has higher precedence than the symbol at the stack top, push that symbol onto the stack

• Otherwise, pop

• Pop all operators off stack when you reach end of expression.

1.) X*Y-(P+Q)*(R/S)

2.) E-F*G/(P+Q)+T

3.) M+L/K*U

1.) X*Y-(P+Q)*(R/S) = XY*PQ+RS/*-

2.) E-F*G/(P+Q)+T = EFG*PQ+/-T+

3.) M+L/K*U = MLK/U*+

1.) 3 5 7 - + 3 2 9 * / -

2.) 4 3 – 2 3 * 5 8 - + 4 - * 2 +

3.) 7 5 3 - + 3 / * 4 2 +

1.) 3 5 7 - + 3 2 9 * / - Valid

2.) 4 3 – 2 3 * 5 8 - + 4 - * 2 + Valid

3.) 7 5 3 - + 3 / * 4 2 + Invalid