1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
oee [108]
3 years ago
12

Prepare a algorithm visualization for the Tower of Hanoi when 4 disks are to be moved from spindle #1 to spindle #3.

Computers and Technology
1 answer:
Setler [38]3 years ago
6 0

Answer:

follwing is the code for Tower of Hanoi for n disks.

#include <iostream>

using namespace std;

void towofhan(int n,char source,char aux,char dest)//function for tower of hanoi..

{

if(n<0)

return ;

   if(n==1)//base case.

   {

       cout<<"Move disk 1 from "<<source<<" to spindle "<<dest<<endl;

       return;

   }

   towofhan(n-1,source,dest,aux);//recursive call.

   cout<<"move disk "<<n<<" from "<<source<<" to spindle "<<dest<<endl;

   towofhan(n-1,aux,source,dest);//recursive call.

}

int main() {

   int n=4;

   towofhan(n,'1','2','3');//function call.

   return 0;

}

Explanation:

If there is only 1 disk then we have to move the disk from source to destination.

Then after that we will apply recursion to solve the problem.

We have to work on only nth disk else will be done by the recursion.

First call recursion to move n-1 disks from source to auxiliary.

Then move nth disk from source to destination spindle.

Now move n-1 disks that are on the auxiliary spindle to destination spindle.

You might be interested in
The text between and defines the _____.
Genrish500 [490]
Active text on a page
5 0
3 years ago
There are three types of value for money. Which of the following is not a method of value?
AlladinOne [14]
The answer to this question is c
4 0
3 years ago
Write a program that will take an integer and add up each of the number’s digits, count the number of digits in the number, and
Inga [223]
For count digits, you could just convert it to a String and check the length
Sum digits, convert to string then seperate each character with charAt then convert it to numbers in the return statement.
Average digits you can convert it to a String and then convert them back after taking them apart.
5 0
3 years ago
Read 2 more answers
Hot components or sharp edges of computer is an example of what hazard​
Alexxandr [17]

Answer:

hot components or sharp edges of computer is an example of a mechanical hazard

6 0
3 years ago
Write an algorithm to get the value of length and breadth of a rectangle from the user and find its area. inn qbasic
Shalnov [3]

Answer:

IN PYTHON ::

x=int(input('Enter length:'))

y=int(input('Enter width:'))

print('Area of the rectangle is', x*y,'squared units')

I hope it will be useful.

5 0
3 years ago
Other questions:
  • To enter a typed number into a cell, you press Tab or Backspace?​
    7·2 answers
  • Given an array of n distinct integers,d = [d[0], d[1],.., d[n - 1]], and an integer threshold, t, how many (a,b,c) index triplet
    11·1 answer
  • Which type of operating system is usually used in personal computers
    13·1 answer
  • Users of Adobe Reader, created by Adobe Systems Incorporated, are prompted to provide feedback on their experiences with the sof
    7·1 answer
  • Hey yall wanna send me some just ask for my phone #
    13·1 answer
  • What are the benefits of building redundancy into a network?
    12·1 answer
  • NEED HELP ASAP!!!!!!
    7·2 answers
  • What is the outcome when a floating-point number is divided by zero?
    12·1 answer
  • Which statement is true?
    13·2 answers
  • Which of the following best describes a hotspot as
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!