Created
April 12, 2017 12:30
-
-
Save lasagnaphil/6f88c49fe47c36985fd081007443272f to your computer and use it in GitHub Desktop.
Hanoi skeleton (java)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Hanoi hanoi = new Hanoi(); | |
hanoi.run(); | |
} | |
} | |
class Hanoi | |
{ | |
private HanoiTower[] towers; | |
private int numOfDisks; | |
private int turns; | |
private Scanner scanner; | |
public Hanoi() | |
{ | |
turns = 0; | |
scanner = new Scanner(System.in); | |
System.out.println("Enter number of disks : "); | |
numOfDisks = scanner.nextInt(); | |
towers = new HanoiTower[3]; | |
for (int i = 0; i < 3; i++) | |
{ | |
towers[i] = new HanoiTower(numOfDisks); | |
} | |
towers[0].insertAllDisks(); | |
} | |
public void run() | |
{ | |
turns = 0; | |
executeTurn(numOfDisks, towers[0], towers[1], towers[2]); | |
System.out.println("Minimum number of moves : " + turns); | |
} | |
private void executeTurn(int n, HanoiTower source, HanoiTower via, HanoiTower dest) | |
{ | |
// ... | |
} | |
public void draw() | |
{ | |
// ... | |
} | |
private void drawDisk(int n, int diskSize) | |
{ | |
// ... | |
} | |
public int getNumOfDisks() { return numOfDisks; } | |
public int getTurns() { return turns; } | |
} | |
class HanoiTower | |
{ | |
private final int maxDisks; | |
private int[] disks; | |
private int diskCount; | |
public HanoiTower(int maxDisks) { | |
// ... | |
} | |
public void insertAllDisks() { | |
// ... | |
} | |
public void insertDisk(int diskSize) { | |
// ... | |
} | |
public int removeDisk() { | |
// ... | |
} | |
// getters | |
public int[] getDisks() { return disks; } | |
public int getDiskCount() { return maxDisks; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment