PROGRAMACION ARBOL EN MONTON ESTRUCTURAS DE DATOS


#include <conio.h>

#include <iostream.h>

class Arbol_Monton

{

private:

int Arbol[25];

int N;

public:

Arbol_Monton()

{

for(int i=0;i<25;i++)

Arbol[i]=0;

N=0;

}

void Insertar(int a)

{

if(N<25)

{

Arbol[N]=a;

N++;

OrdMon(N);

return;

}

cout<<"Arbol Lleno..."<<endl;

}

void Eliminar(int a)

{

int t;

if(N!=0)

{

OrdMon(N);

for(int i=0;i<N;i++)

{

if(Arbol[i]==a)

{

for(int j=i+1;j<N;j++)

{

t=Arbol[i];

Arbol[i]=Arbol[j];

Arbol[j]=t;

}

N--;

cout<<"Elemento Eliminado..."<<endl;

return;

}

}

}

cout<<"Arbol Vacio... Imposible Eliminar..."<<endl;

}

void Busqueda(int a)

{

if(N!=0)

{

OrdMon(N);

for(int i=0;i<N;i++)

if(Arbol[i]==a)

{

cout<<"Elemento Encontrado..."<<endl;

return;

}

cout<<"El Elemento no esta en el Arbol..."<<endl;

return;

}

cout<<"Arbol Vacio..."<<endl;

}

void OrdMon(int n)

{

ConstMon(n);

while(n>1)

{

n--;

Burbuja(0,n);

RecMon(n,0);

}

}

void ConstMon(int n)

{

for(int v=n/2-1;v>=0;v--)

RecMon(n,v);

}

void RecMon(int n,int v)

{

int w=2*v+1;

while(w<n)

{

if(w+1<n)

if (Arbol[w+1]>Arbol[w])

w++;

if(Arbol[v]>=Arbol[w])

return;

Burbuja(v,w);

v=w;

w=2*v+1;

}

}

void Burbuja(int i,int j)

{

int t=Arbol[i];

Arbol[i]=Arbol[j];

Arbol[j]=t;

}

void Recorrido()

{

if(N!=0)

{

for(int i=0;i<N;i++)

cout<<Arbol[i]<<endl;

return;

}

cout<<"Arbol Vacio..."<<endl;

}

}tec;

main()

{

int res,op=0;

while(op!=5)

{

clrscr();

cout<<"\n1) Recorrido\n2) Busqueda\n3) Insercion\n4) Eliminar\n5) Salir"<<endl;

gotoxy(1,1);

cout<<"Que deseas hacer?: ";

cin>>op;

gotoxy(1,10);

switch (op)

{

case 1:

tec.Recorrido();

break;

case 2:

cout<<"Que Numero deseas buscar?"<<endl;

cin>>res;

tec.Busqueda(res);

break;

case 3:

cout<<"Que Numero quieres Insertar?"<<endl;

cin>>res;

tec.Insertar(res);

break;

case 4:

cout<<"Que Numero quieres Eliminar?"<<endl;

cin>>res;

tec.Eliminar(res);

break;

case 5:

cout<<"Salida...";

break;

default:

cout<<"Opcion Erronea"<<endl;

break;

}

getch();

}

}

 




Google
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
Politica de Privacidad