Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
5Activity
0 of .
Results for:
No results containing your search query
P. 1
Arbol..

Arbol..

Ratings: (0)|Views: 365|Likes:
Published by Erika

More info:

Published by: Erika on Apr 28, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

11/08/2012

pdf

text

original

 
ÁRBOL 
class
NodoArbol{NodoArbolli,ld;
int
 dato;
public
NodoArbol(
int
d){dato=d;li=ld=
null
;}
public
 
synchronized
 
void
insertar(
int
d){
if 
(d<dato){
if 
(li==
null
){li=
new
NodoArbol(d);}
else
{li.insertar(d);}}
if 
(d>dato){
if 
(ld==
null
){ld=
new
NodoArbol(d);}
else
{ld.insertar(d);}}}//fin insertar  
public
 
int
retornadato(){
return
(dato);}//end retornadato }
public
 
class
Arbol {
private
NodoArbolraiz;
public
Arbol() {raiz=
null
;
 
}
public
NodoArbol retornaraiz(){
return
(raiz);}
public
 
synchronized
 
void
insertarNodo(
int
d){
if 
(raiz==
null
){raiz=
new
NodoArbol(d);//primero=raiz; }
else
{raiz.insertar(d);}}//fin insertarNodo 
public
 
synchronized
String preorden(){String pre=ayudantepreorden(raiz);
return
(pre);}
private
String ayudantepreorden(NodoArbol nodo){String cadena=
new
String();
if 
(nodo!=
null
){//return; //System.out.print(nodo.dato+" "); cadena=cadena+String.
valueOf 
(nodo.dato+" "); cadena=cadena+ayudantepreorden(nodo.li);cadena=cadena+ayudantepreorden(nodo.ld);}
else
{cadena="";}
return
(cadena);}
public
 
synchronized
String inorden(){String inor=ayudanteinorden(raiz);
return
(inor);}
private
String ayudanteinorden(NodoArbol nodo){String cadena=
new
String();
if 
(nodo!=
null
){// return; 
 
cadena=cadena+ayudanteinorden(nodo.li);cadena=cadena+nodo.dato+" "; cadena=cadena+ayudanteinorden(nodo.ld);}
else
{cadena="";}
return
(cadena);}
public
 
synchronized
String posorden(){String pos=ayudanteposorden(raiz);
return
(pos);}
private
String ayudanteposorden(NodoArbol nodo){String cadena=
new
String();
if 
(nodo!=
null
){cadena=cadena+ayudanteposorden(nodo.li);cadena=cadena+ayudanteposorden(nodo.ld);cadena=cadena+nodo.dato+" "; }
else
{cadena="";}
return
(cadena);}
public
 
synchronized
 
int
altura(NodoArbol R){NodoArbol p=R;
int
altizq=p.li==
null
? 1:1+altura(p.li);
int
altder=p.ld==
null
? 1:1+altura(p.ld);
return
(Math.
max 
(altizq,altder));}//end altura 
public
 
synchronized
 
int
hojas(NodoArbol R){NodoArbol p=R;
int
hojas=0;
if 
(p.li==
null
& p.ld==
null
){hojas=1;}
else
{
if 
(p.li!=
null
){hojas=hojas+hojas(p.li);}
if 
(p.ld!=
null
){hojas=hojas+hojas(p.ld);}

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->