This algorithm reads the value of number of discs and prints the move that are to be done for playing towers of hanoi.
Pre: n is a positive integer which carries the value of number of discs.
Post: prints the moves that are to be done for transferring discs in ascending order in another peg
1.initialize value of n(positive integer greater than 1)
2.moves = pow(2,disk)-1
3.if(n=1)
i) moves disk from "from" to "to"
4. end if
5. else
i)hanoi(n-1,from,aux,to)
ii) moves disc from "from" to "to''
iii) hanoi(n-i,from,aux,to)
6.end else
7. prints the moves
end towers_of_hanoi
Copyright © 2026 eLLeNow.com All Rights Reserved.