Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q5 IN JAVA: Modify the following code to print out the disk backup schedule for disks A-E (5 disks) public class TowerOfHanoi3 { public static

Q5 IN JAVA: Modify the following code to print out the disk backup schedule for disks A-E (5 disks)

public class TowerOfHanoi3 { public static void main (String[] argv) { // A 5-disk puzzle: solveHanoi (4, 0, 1); } static void solveHanoi (int n, int i, int j) { // Bottom-out. if (n == 0) { // The smallest disk. move (0, i, j); return; } int k = other (i, j); solveHanoi (n-1, i, k); // Step 1. move (n, i, j); // Step 2. solveHanoi (n-1, k, j); // Step 3. } static void move (int n, int i, int j) { // INSERT YOUR CODE HERE. // Before printing, convert n=0 to 'A', n=1 to 'B' etc. } static int other (int i, int j) { // Given two towers, return the third. if ( (i == 0) && (j == 1) ) { return 2; } else if ( (i == 1) && (j == 0) ) { return 2; } else if ( (i == 1) && (j == 2) ) { return 0; } else if ( (i == 2) && (j == 1) ) { return 0; } else if ( (i == 0) && (j == 2) ) { return 1; } else if ( (i == 2) && (j == 0) ) { return 1; } // We shouldn't reach here. return -1; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions