Download presentation
Presentation is loading. Please wait.
Published byDwayne Booker Modified over 6 years ago
1
COMPUTER 2430 Object Oriented Programming and Data Structures I
2
Binary Arithmetic Operations
Addition (plus): + Subtraction (minus): - Multiplication (times): * Division: / Remainder: % operand1 operator operand2 12 + 5 3 * (7 – 4 * 5)
3
Binary Arithmetic Operations
Infix A + B Prefix + A B Postfix (RPN) A B +
4
Binary Arithmetic Operations
Infix Prefix and Postfix (RPN) Don’t need parentheses (No commutative law) (No associative law) (No distributed law)
5
Examples What are the operands (A, B and C)? Integers Double
Infix (A + B) * C A + (B * C) Prefix * + A B C + A * B C Postfix (RPN) A B + C * A B C * + What are the operands (A, B and C)? Integers Double Complex Numbers FixedPoint Numbers (Prog2) TVectors (Prog3)
6
Evaluating Prefix Expression
* * 16 / * * -17 From left to right Perform the operation when an operator is followed by two operands
7
Evaluating Postfix Expression
* * 16 4 / * * -17 From left to right Perform the operation when an operator follows two operands
8
Converting Prefix Expressions to Infix
* * (5 + 3) (5 + 3) * 2 / * (12 / 4) * (1 + 3) (12 / 4) (5 * (1 + 3) ) (12 / 4) – (5 * (1 + 3) ) From left to right, add parentheses when an operator is followed by two operands and move the operator (a pair of parentheses is an operand) Original operands remain in the same order!
9
Converting Prefix Expressions to Infix
* A B C * A (B + C) A * (B + C) / A B * C D E (A / B) * (C + D) E (A / B) ( (C + D) * E) (A / B) – ( (C + D) * E) From left to right, add parentheses when an operator is followed by two operands and move the operator (a pair of parentheses is an operand) Original operands remain in the same order!
10
Converting Infix Expressions to Prefix
A * (B + C) * A (B + C) * A + B C A * (B + C) A * (+ B C) * A (+ B C) * A B C Move operator to the front and remove parentheses when it’s clear Original operands remain in the same order!
11
Converting Infix Expressions to Prefix
(A / B) - ( (C + D) * E) - (A / B) ( (C + D) * E) - (/ A B) ( * (C + D) E) - (/ A B) ( * (+ C D) E) - (/ A B) ( * + C D E) - / A B * + C D E (/ A B) - ( (+ C D) * E) (/ A B) - ( * (+ C D) E) (/ A B) - ( * + C D E) - (/ A B) ( * + C D E) - / A B * + C D E Move operator to the front and remove parentheses when it’s clear Original operands remain in the same order!
12
Converting Postfix Expressions to Infix
A B C * A (B + C) * A * (B + C) A B / C D E * - (A / B) (C + D) E * - (A / B) ( (C + D) * E) (A / B) ( (C + D) * E) Add parentheses when two operands followed by an operator and move the operator Original operands remain in the same order!
13
Converting Infix Expressions to Postfix
A * (B + C) A (B + C) * A (B C +) * A B C * A * (B + C) A * (B C +) A (B C +) * A B C * Move operator to the end and remove parentheses when it’s clear Original operands remain in the same order!
14
Converting Infix Expressions to Postfix
(A / B) - ( (C + D) * E) (A / B) ( (C + D) * E) (A B /) ( (C + D) E *) (A B /) ( (C D +) E *) (A B /) ( C D E *) A B / C D E * (A B /) - ( (C D +) * E) (A B /) - ( (C D +) E *) (A B /) - ( C D + E *) (A B /) ( C D + E *) - A B / C D + E * - Move operator to the front and remove parentheses when it’s clear Original operands remain in the same order!
15
Exercise
16
Quiz 3
17
Lab 4
18
Lab 5
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.