Estructura de arboles
#include
#include "conio.h"
#include "arbol.h"
void InicializarABB(pArbol &A)
{
A=NULL;
}
//MOVIMIENTO EN ABB
void MostrarDato(int Dato)
{
printf("%d",Dato);
}
void InOrden(pArbol &A)
{
if(A!=NULL)
{
InOrden(A->izq);
MostrarDato(A->Dato);
InOrden(A->der);
}
}
void PreOrden(pArbol &A)
{
if(A!=NULL)
{
MostrarDato(A->Dato);PreOrden(A->izq);
PreOrden(A->der);
}
}
void PosOrden(pArbol &A)
{
if(A!=NULL)
{
PosOrden(A->izq);
PosOrden(A->der);
MostrarDato(A->Dato);
}
}
//INFORMACION DE ABB
int ArbolVacio(pArbol&A)
{
if(A==NULL)
return 1;
else
return 0;
}
int EsHoja(pArbol &A)
{
if((A->der==NULL)&&(A->izq==NULL))
return 1;
else
return 0;
}
void NumerosDeNodos(pArbol &A, int &x)
{if(A!=NULL)
{
x++;
NumerosDeNodos(A->izq,x);
NumerosDeNodos(A->der,x);
}
}
int CantidadDeNodos(pArbol &A)
{
int Cantidad=0;
if(A!=NULL)
NumerosDeNodos(A,Cantidad);
return Cantidad;
}
intAlturaDeUnNodo(pArbol &A, int x)
{
int Altura=0;
Nodo Aux=A;
while(Aux!=NULL)
{
if(x==Aux->Dato)
return Altura;
else
{
Altura++;
if(x>Aux->Dato)
Aux=Aux->der;
else
Aux=Aux->izq;
}
}if(Altura==0)
return 1;
return Altura;
}
void VaciarABB(pArbol &A)
{
if(A!=NULL)
{
VaciarABB(A->izq);
VaciarABB(A->der);
delete(A);
}
A=NULL;
}
int AlturaArbol(pArbol &A)
{
intAltDer=0,AltIzq=0;
if(A==NULL)
return -1;
else
{
AltIzq=AlturaArbol(A->izq);
AltDer=AlturaArbol(A->der);
if(AltIzq>AltDer)
AltIzq=AltIzq+1;
else
AltIzq=AltDer+1;
}
return AltIzq;
}//OPRECIONES EN ABB
int BuscarMenorEnABB(pArbol &A)
{
Nodo Aux=A;
if(Aux!=NULL)
{
while(Aux->izq!=NULL)
Aux=Aux->izq;
}
return (Aux->Dato);
}
int BuscarMayorEnABB(pArbol &A)
{
Nodo Aux=A;if(Aux!=NULL)
{
while(Aux->der!=NULL)
Aux=Aux->der;
}
return (Aux->Dato);
}
int BuscarElementoEnABB(pArbol &A, int x) // 1: Encontado, 0: No Existe
{
Nodo Aux=A;
if(Aux!=NULL)
{...
Regístrate para leer el documento completo.