To code the solution we will develop a function “move”. Shift the only remaining disk from tower C to tower B.Now we are left with 3 disks in tower B that are perfectly arranged and single disk remaing in tower C.Let’s now shift the topmost disk from tower A to tower C.And shift the last disk from tower C to tower B.Now shift the first 2 disks from tower C to tower A Tower Of Hanoi Program In C Using Graphics In Word Recursive solution A key to solving this puzzle is to recognize that it can be solved by breaking the problem down into a collection of smaller problems and further breaking those problems down into even smaller problems until a solution is reached.Shift the only disk remaining in tower A to tower B.Shift top 3 disks from tower A to tower C(Iterations Needed: 3).And then we repeat the same procedure for the remaining disks.įor example, consider the case with 4 disks, Notice that now we just need to shift the remaining N – 1 disks from tower B to tower Cīasically, we shift the disks from one tower to the second tower by taking the help of the third tower.Then shift the bottom most disk to tower C.We shift the top N – 1 disks from tower A to the tower B.And tower ‘A’ initially contains all the disks. Let’s suppose that the towers are named as ‘A’, ‘B’, and ‘C’.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |