السلام عليكم
ممكن تساعدوني بكتابة برنامج Tower of Hanoi
شكرا لكم
وكل عام و أنت بخير
السلام عليكم
ممكن تساعدوني بكتابة برنامج Tower of Hanoi
شكرا لكم
وكل عام و أنت بخير
The initial stack has number of disks threaded onto one peg and arranged from bottom to top by decreasing size, attempting to move the stack from this peg to a second peg under constraints that exactly one disk is moved at a time and at no time may a larger disk be placed above a smaller disk , a third peg is available for temporarily holding disks.
Please send to me the recursive method code to move the number of disks from peg1 to peg3
و شكرا كثيرا أي اقتراح
و إذا أرتم أي توضيح أنا مستعد
import java.io.*;
public class hanoi
{
public static void main(String[] args) throws IOException
{
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
int disks;
System.out.println("Enter number of disks: ");
disks = Integer.parseInt(stdin.readLine());
doHanoi(disks, "1", "3", "2");
}
public static void doHanoi(int disks, String start, String end, String temp)
{
if (disks >= 1)
{
doHanoi(disks - 1, start, temp, end);
System.out.println("Move 1 disk from " + start + " to " + end);
doHanoi(disks - 1, temp, end, start);
}
}
}
شكرا
و جزاك الله كل خير
هذا الموضوع مغلق.