Question: Please follow the instruction help me use C++ language solve it and also I can run it successfully Towers Hanoi) In chapter 6. you studied
Please follow the instruction help me use C++ language solve it and also I can run it successfully Towers Hanoi) In chapter 6. you studied functions that can be easily implememedbochrecursively and iteratively. In this exercise, we present a problem whose recursive solution demonstranes the elegance of recursion, and whose iterative solution may no be as The Towers of Hanoi is one of the most famous dassic problems every budding computer sdentisa must grapple with. Legend has it that in a temple inthe Far East, priests to move a saack of golden disks from one diamond pegto another (Illustration 10.The initial stackhas6adisksthreaded onto one peg and amanged from botlom to top by decreasing size The priests are amemptingto move the stack from one peg to anocher under the constraints tat exactly one disk is meved ata time and no time may a larger disk be placed above a smaller disk. Three pegs are being used for temporarily holding disks. Supposedly the world will end when the priests complemether sothere is little incentive for us to facilitate their efforts. Let's assume that the priests to move the disks from peg I tolpeg 3. Wie wish to develop algorithm that printsthe precise sequence peg torpeg disk transfers. approach this problem with conventional methods, we would rapidly find ourselves hopelessly knotted up in managing the disks. Instead attacking this problem withrecursion in mind allows the steps to be simple. Moving n disks can be viewed in termsof moving onlyn-l disasChemor. as follows: the recursion) a) Move n-1 disks from peg Ito peg 2, using peg 3 as a temporary holding b) Move the last disk (the largest) from peg ltopeg 3 temporary holding Move the n disks from peg 2 Do Peg ,using Peg 1 as a 1: Towers of Hanoi he case with four disks The process ends when the last task involves moving 1 disk (ie, the base case This task is accomplished by simply moving the dik, without the need for a temporary holding area while a Program to solve the Towers of Hanoi Peoblem. Use arecursive function with fourParammers: a) The number of disks to be moved The peg to which this stack of disks is to be moved d) The peg to be used as temporary holding area Display the precise instructions for moving the disas from the sunting peg to the destination peg To move aslack of three disks from peg 1topeg3the program displays the following (This means move one disk from peg 1 to peg3) NOTE: 2) The output should be near Multiple files should be used
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
