Codigo java torre de hanoi

Páginas: 3 (749 palabras) Publicado: 4 de junio de 2011
TORRES DE HANOI
TORRES DE HANOI


DEFINICION DEL PROBLEMA
Elaborar un programa que realice el método de torres de hanoi.
DEFINICION DE SOLUCION
Se tendrán que pasar los discos a la barra 3 ode acuerdo cuantas barras y discos desees, de tal manera que queden igual.

DESARROLLO DEL PROBLEMA
import java.awt.*;
import java.applet.*;
public class Hanoi extends Applet
{
static final intXDOTS = 400;
static final int YDOTS = 200;
static final int NULL = -1;
static final int MAX = 20;
static final int MIN = 3;
static final int MAXCOLS = 6;
static final int MINCOLS = 3;
staticfinal Color cfondo=new Color(228,233,243);
static final Color cbarra=Color.black;
static final Color cfin =Color.red;
static final Color ctorre=Color.black;
boolean first=true;
int origen,destino;int movimientos;
int h[] = new int[MAXCOLS];
int Ficha[][] = new int[MAXCOLS][MAX];
int Centorr[] = new int[MAXCOLS];
Button B[] = new Button[MAXCOLS];
TextField TFTorres, TFCols,TFMovimientos;
int numtorres=5, numcols=3;
void Parametros()
{
String param;
param = getParameter("TORRES");
if (param != null) numtorres = Integer.parseInt(param);
param = getParameter("COLS");
if (param!= null) numcols = Integer.parseInt(param);
}
public void init()
{
int i;
setBackground(cfondo);
resize(XDOTS,YDOTS);
if (first)
{
Parametros();
Herramientas();
first=false;
}
for (i=0;i< MAXCOLS; i++)
if (i< numcols) B[i].enable();
else B[i].disable();
for (i=0; i< numcols; i++)
Centorr[i]=(XDOTS/(numcols+1))*(i+1);
h[0]=numtorres;
for (i=1; i< numcols; i++)h[i]=0;
for (i=0; i< numtorres; i++)
Ficha[0][i]=numtorres-i;
movimientos=0;
origen=destino=NULL;
}
public void Herramientas()
{
setLayout(new BorderLayout());
Panel p= new Panel();p.setBackground(cfondo);
for (int i=0; i< MAXCOLS; i++)
p.add(B[i]=new Button(Integer.toString(i+1)));
p.add(new Button("Cancelar"));
p.add(new Button("Solucion"));
p.add(new Button("Nueva"));...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Torres de hanoi
  • Torres de hanoi
  • TORRES DE HANOI
  • Torre de hanoi
  • Torre de hanoi
  • Torres de hanoi
  • Torre de hanoi
  • torres de hanoi

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS