Line Ards
Line Ards
AB-C- ABC--
Arithmetic Expression (4)
But how do we read it?
Can the Polish people really understand this?
12+31+x2/
Arithmetic Expression (5)
Algorithm for Computing Postfix
Arithmetic Expression:
Data Structures: A[1..n] - a legal arithmetic
expression in postfix notation.
E - a stack of
evaluated parts of the expression.
endFor
POP(E,Solution)
Arithmetic Expression (7)
Example: 12+31+x2/ ((1+2)x(3+1))/2=6
operator
1 + 2 3=
2
1
3
Arithmetic Expression (7)
Example: 12+31+x2/ ((1+2)x(3+1))/2=6
operator
3 + 1 4=
1
3
4
3
Arithmetic Expression (7)
Example: 12+31+x2/ ((1+2)x(3+1))/2=6
operator
3 x 4 12=
4
2
12
3
Arithmetic Expression (7)
Example: 12+31+x2/ ((1+2)x(3+1))/2=6
6
operator
12 / 2 6=
2
12
6
Arithmetic Expression (8)
Exercise:
Telephone switches
Then…
A B C
Subroutines: CALL B CALL C CALL A
Context Saving (3)
Software:
Recursive Subroutines:
A
CALL A
Example: Sudoku.
Context saving: LIFO.