Write Algorithm/Pseudo-code to solve Tower of Hanoii

Alorithm Hanoii(n,source,temp,target)

 if(n>=1)
 begin
   move n-1 discs to intermediate pole using target pole as intermediate pole
   Hanoii(n-1,source,target,temp)
   print "Move source to target"
   move n-1 discs to target pole using source pole as intermediate
   Hanoii(n-1,temp,source,target)
 end
end algorithm

No comments:

Post a Comment