solved s04 ex1

This commit is contained in:
navid.sassan 2020-10-18 23:40:00 +02:00
parent cf2e3e5b98
commit b58db20935

View File

@ -0,0 +1,23 @@
package ch.zhaw.ads;
public class HanoiServer implements CommandExecutor {
@Override
public String execute(String command) {
int n = Integer.parseInt(command);
return moveDisk(n, 'A', 'B', 'C');
}
public String moveDisk(int n, char from, char to, char help) {
String out = "";
if (n > 0) {
// bewege Stapel n-1 von from auf help
out += moveDisk(n-1, from, help, to);
// bewege von from nach to
out += "move " + from + " to " + to + "\n";
// bewege Stapel n-1 von help auf to
out += moveDisk(n-1, help, to, from);
}
return out;
}
}