NOMBRE DEL ALUMNO: DIANA KARINA GARCIA JACOME
NOMBRE DE LA MAESTRO: SALVADOR CONTRERAS HERNANDEZ
GRUPO: 110-352
ASIGNATURA: PROGRAMACION ESTRUCTURADA
TEMA: PROGRAMA DE LAS “TORRES DE HANOI”
FECHA DE ENTREGA: 25-JULIO-2017
CLASE PRINCIPAL (JUEGO TORRES) package juegotorres;
public class JuegoTorres {
public static void main(String[] args) ; Hanoi r = new Hanoi(); System.out.println(" **************************************** "); System.out.println(" Metodo iterativo :v "); System.out.println(" "); r.Metodo(3, 1, 2, 3); System.out.println(" "); System.out.println(" **************************************** "); System.out.println(" r.Recursivo(3, 1, 3, 2); } }
Metodo recursivo :v ");
SUB-CLASE (HANOI) package juegotorres; public class Hanoi { public void Metodo(int n, int origen, int destino, int aux){ int pilaN [] = new int [10]; int pilaO [] = new int [10]; int pilaD [] = new int [10]; int pilaX [] = new int [10]; int tope = 0; int varaux; boolean band = false;
while(n > 0 && band == false){ while(n > 1){ tope++; pilaN[tope] = n; pilaO[tope] = origen; pilaD[tope] = destino; pilaX[tope] = aux;
n--; varaux = destino; destino = aux; aux = varaux; } System.out.println(" Mueve disco de " + origen + " a " + destino); band = true; if (tope > 0){ n = pilaN[tope]; origen = pilaO[tope]; destino = pilaD[tope]; aux = pilaX[tope]; tope--; System.out.println(" Mueve un disco de " + origen + " a " + destino); n--; varaux = origen; origen = aux;
aux = varaux; band = false; } } }
public void Recursivo (int n, int origen, int aux, int destino){ if(n == 1){ System.out.println(" Mueve un disco " + origen + " a " + destino); } else{ Recursivo(n - 1, origen, destino, aux); System.out.println(" Mueve un disco de " + origen + " a " + destino); Recursivo(n - 1, aux, origen, destino); } } }
NOMBRE DEL ALUMNO: EDER ALAN MEDINA NAVARRETE
NOMBRE DE LA MAESTRO: SALVADOR CONTRERAS HERNANDEZ
GRUPO: 110-352
ASIGNATURA: PROGRAMACION ESTRUCTURADA
TEMA: PROGRAMA DE TORRES DE HANOI
FECHA DE ENTREGA: 25-JULIO-2017
CLASE PRINCIPAL (TORRESHANOI) package torreshanoi;
public class TorresHanoi {
public static void main(String[] args) { // TODO code application logic here Hanoi objeto = new Hanoi(); System.out.println(" **************************************** "); System.out.println(" Metodo iterativo :v "); System.out.println(" "); objeto.Metodo(3, 1, 2, 3); System.out.println(" "); System.out.println(" **************************************** "); System.out.println(" objeto.Recursivo(3, 1, 3, 2); } }
Metodo recursivo :v ");
SUB-CLASE (METODOS) package torreshanoi; public class Metodos { public void Iterativo(int n, int origen, int destino, int aux){ int pilaN [] = new int [10]; int pilaO [] = new int [10]; int pilaD [] = new int [10]; int pilaX [] = new int [10]; int tope = 0; int varaux; boolean band = false;
while(n > 0 && band == false){ while(n > 1){ tope++; pilaN[tope] = n; pilaO[tope] = origen; pilaD[tope] = destino; pilaX[tope] = aux;
n--; varaux = destino; destino = aux; aux = varaux; } System.out.println(" Mueve disco de " + origen + " a " + destino); band = true; if (tope > 0){ n = pilaN[tope]; origen = pilaO[tope]; destino = pilaD[tope]; aux = pilaX[tope]; tope--; System.out.println(" Mueve un disco de " + origen + " a " + destino); n--; varaux = origen; origen = aux;
aux = varaux; band = false; } } } public void Recursivo (int n, int origen, int aux, int destino){ if(n == 1){ System.out.println(" Mueve un disco " + origen + " a " + destino); } else{ Recursivo(n - 1, origen, destino, aux); System.out.println(" Mueve un disco de " + origen + " a " + destino); Recursivo(n - 1, aux, origen, destino); } } }