Creación De Un Arbol En C++
Enviado por risuor • 17 de Mayo de 2012 • 501 Palabras (3 Páginas) • 528 Visitas
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <conio2.h>
struct arbol{
int info;
struct arbol *left;
struct arbol *right;
};
typedef struct arbol nodetree;
typedef nodetree *arbolptr;
void insertar(arbolptr*L, int b);
void imprimir(arbolptr L);
void preorden(arbolptr L);
void inorden(arbolptr L);
void posorden(arbolptr L);
void menu();
void pintar();
void portada();
main()
{
pintar();
arbolptr L=NULL;
int inf, opcion;
menu(),
(" n Seleciona la opcion: n");
scanf("%d",&opcion);
while(opcion!=6){
switch(opcion)
{
case 1:{
pintar();
portada();
printf(" nn");
system("pause");
menu();
break;
}
case 2:{
pintar();
printf("n INTRODUZCA UN ELEMENTO: ");
scanf("%d",&inf);
insertar(&L,inf);
imprimir(L);
printf(" nn");
system("pause");
menu();
break;
}
case 3: {
pintar();
printf("nn VISUALIZACION DEL ARBOL EN PRE-ORDEN: ");
preorden(L);
printf(" nn");
system("pause");
menu();
break;
}
case 4: {
pintar();
printf("nn VISUALIZACION DEL ARBOL EN IN-ORDEN: ");
inorden(L);
printf(" nn");
system("pause");
menu();
break;
}
case 5: {
pintar();
printf("nn VISUALIZACION DEL ARBOL EN POST-ORDEN: ");
posorden(L);
printf(" nn");
system("pause");
menu();
break;
}
case 6: {
printf("Fin del programa");
break;
}
default:
printf("OPCION INVALIDA");
menu();
break;
}
printf(" nn");
menu();
scanf("%d",&opcion);
}
return 0;
}
void menu()
{
textbackground(11);
clrscr();
textcolor(12);
printf("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&n");
printf(" n");
printf(" PROGRAMA PARA TRABAJAR CON ARBOLES n");
printf(" n");
printf(" 1 - PORTADAn");
printf(" 2 - INCORPORACION DE LA INFORMACION n");
printf(" 3 - VISUALIZAR EL ARBOL EN PRE-ORDEN n");
printf(" 4 - VISUALIZAR EL ARBOL EN IN-ORDEN n");
printf(" 5 - VISUALIZAR EL ARBOL EN POST-ORDEN n");
printf(" 6 - SALIR n");
printf(" n");
printf("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&n");
...