solved s04 ex1
This commit is contained in:
parent
cf2e3e5b98
commit
b58db20935
23
04/src/main/java/ch/zhaw/ads/HanoiServer.java
Normal file
23
04/src/main/java/ch/zhaw/ads/HanoiServer.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user