Stack
Stack
Stack
1
2
3
Source = ‘A’ Intermediate = ‘B’ Destination = ‘C’
In this problem we transfer all disks from origin tower to destination tower using
intermediate tower for temporary storage and move only one disk at a time.
1
2
3
Source = ‘A’ Intermediate = ‘B’ Destination = ‘C’
1
2
3
Source = ‘A’ Intermediate = ‘B’ Destination = ‘C’
1
3 2 1st disc C->B
Source = ‘A’ Intermediate = ‘B’ Destination = ‘C’
1
2 3 3rd disc A->C
Source = ‘A’ Intermediate = ‘B’ Destination = ‘C’
1
2 3
Source = ‘A’ Intermediate = ‘B’ Destination = ‘C’
2
1 3 2nd disc B->C
Source = ‘A’ Intermediate = ‘B’ Destination = ‘C’
Prepared By : Vaishali Koria Data Structure and Algorithms 9
Tower of Hanoi
c) Move the (n-1) [2] disks from B to C. ( intermediate to destination)
1
2 1st disc A->C
3
Source = ‘A’ Intermediate = ‘B’ Destination = ‘C’
1st disc A->C 1st disc C->B 1st disc B->A 1st disc A->C
Validity of expressions:
(II) A+B*C+D
(IV) A+B*(C+D)
Inputs:
a #a *,/ 2 -1
variabl 3 1
* # a 1 es
# 0 -
#* a 1
b #*b a 1
+ #*b a 1
+ #* ab 2
#+ ab* 1
c #+c ab* 1
# #+c ab* 1
# ab*c+ 1
Inputs:
+,- 1 2 -1
*,/ 3 4 -1
variable 7 8 -1
( 9 0 1
) 0 - -
Evaluation of postfix expression
Eg., 2 3 +