Towers of hanoi problem, Computer Engineering

Assignment Help:

The Towers of Hanoi Problem

Towers of Hanoi problem is described. There are three pegs on which disks are "threaded" (there are holes in the disks to allow them to be placed on the pegs). No two disks have the same size and one can never place a larger disk stop a smaller disk. Only one disk can be moved at a time (and when a disk is not being move, it must be on one of the pegs). The problems starts with all the disks on one peg and the goal is to move them all to one other peg.

Write a program that solves the Towers of Hanoi problem. However, we want to make some minor changes to the speci?cation provided in the textbook.

Instead of numbering the pegs 1, 2, and 3, number them 0, 1, and 2. You code should start with all the disk on peg 0 and the goal is to move them all to peg 2.

Call the function you write to solve the problem hanoi(). This is a void function. Instead of four parameters (as described in the textbook), the function should take ?ve parameters as follows:

1. The total number of disks on all the pegs.

2. The number of disks to be moved.

3. The peg on which the disks are initially threaded (i.e., the "source" peg).

4. The peg to which these disks are to be moved (i.e., the "destination" peg).

5. The peg to use as a temporary holding peg.

Note that parameters 2 through 5 in the list above are the same as the parameters 1 through 4 as described in the textbook. The only new parameter is the ?rst one and, once initially set, this parameter will not change throughout the remainder of the execution of the program  though not necessary for the solution of this problem, the reason for including this parameter will be more clear in the next problem.


Related Discussions:- Towers of hanoi problem

Convert the decimal number to excess-3 code, Convert the decimal number 430...

Convert the decimal number 430 to Excess-3 code ? Ans. Excess  3  is  a  digital  code  acquired  from  adding  3  to  every  decimal  digit  and  after that converting the res

Show the mailing lists on internet, Q. Show the Mailing lists on Internet? ...

Q. Show the Mailing lists on Internet? Another exciting aspect about E-mail is that you can find groups of people who share your interests-whether you are inclined toward games

What is a thread, What is a thread? A thread otherwise called a lightwe...

What is a thread? A thread otherwise called a lightweight process (LWP) is a basic unit of CPU utilization, it comprises of a thread id, a program counter, a register set and a

Functions of an operating system, Question a) In multitasking Operatin...

Question a) In multitasking Operating Systems, there are two kinds of multitasking such as the "Preemptive Multitasking" and the "Cooperative Multitasking". Explain the two me

What is semaphores, What is semaphores?  A semaphore 'S' is a synchroni...

What is semaphores?  A semaphore 'S' is a synchronization tool which is an integer value that, apart from initialization, is accessed only by two standard atomic operations; wa

Write C++ for following question., We are planning an orienteering game. Th...

We are planning an orienteering game. The aim of this game is to arrive at the goal (G) from the start (S) with the shortest distance. However, the players have to pass all the che

What is an imperative statement, What is an imperative statement? Ans. ...

What is an imperative statement? Ans. Shows an action to be performed throughout execution of assembled program is an imperative statement.

What is class and class diagram, What is class, class diagram? An objec...

What is class, class diagram? An object is an instance of a class. Class explains a group of objects with similar properties (attributes), behaviour (operations), kinds of rela

Define the role of organizationin computer architecture, Define the role of...

Define the role of organizationin computer architecture The organization is the set of resources that realizes the architecture which include the CPU, the memory and I/O contro

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd