begin process at 2008 08 29 08:40:58
1 233 528 membres
67 nouveaux aujourd'hui
14 291 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

RESOLUTION DE LA TOUR DE HANOI...


Information sur la source



Description

Ce code java permet de générer la solution de la tour de Hanoi pour un nombre infini d'anneau par la recursivité.

Source

  • import javax.swing.JOptionPane;
  • public class hanoi {
  • public static void hanoi(int n, String from, String temp, String to) {
  • if (n == 0) return;
  • hanoi(n-1, from, to, temp);
  • System.out.println("Bougez le disque " + n + " de " + from + " à " + to);
  • hanoi(n-1, temp, from, to);
  • }
  • public static void main(String[] args) {
  • String a;
  • int n;
  • a = JOptionPane.showInputDialog("Combien de diques ?");
  • n = Integer.parseInt(a);
  • hanoi(n, "A", "B", "C");
  • }
  • }
import javax.swing.JOptionPane;


public class hanoi {
	    public static void hanoi(int n, String from, String temp, String to) {
	        if (n == 0) return;
	        hanoi(n-1, from, to, temp);
	        System.out.println("Bougez le disque " + n + " de " + from + " à " + to);
	        hanoi(n-1, temp, from, to);
	    }

	    public static void main(String[] args) {
	    	String a;
	    	int n;
	    	a = JOptionPane.showInputDialog("Combien de diques ?");
	    	n = Integer.parseInt(a);
	        hanoi(n, "A", "B", "C");
	    }
}

Sources en rapport avec celle ci

    Aucun commentaire pour le moment.

Ajouter un commentaire

Discussions en rapport avec ce code source

Pub



Appels d'offres

Recherche developpeur ...
Budget : 700€
SITE MARCHAND LOCATION...
Budget : 3 000€
SITE MARCHAND POUR HOTEL
Budget : 4 000€

CalendriCode

Août 2008
LMMJVSD
    123
45678910
11121314151617
18192021222324
25262728293031

Téléchargements

Boutique

Boutique de goodies CodeS-SourceS