Advertisement
plantbae

codigo clase

May 4th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <locale.h>
  4. #include <wchar.h>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. struct nodo
  10. {
  11.     int nro;
  12.     struct nodo *izq, *der;
  13. };
  14.  
  15. typedef struct nodo *abb;
  16.  
  17. abb crearNodo(int x)
  18. {
  19.     abb nuevoNodo = new(struct nodo);
  20.     nuevoNodo->nro = x;
  21.     nuevoNodo->izq = NULL;
  22.     nuevoNodo->der = NULL;
  23.     return nuevoNodo;
  24. }
  25.  
  26. void insertar(abb &arbol, int x)
  27. {
  28.     if (arbol==NULL)
  29.     {
  30.         arbol = crearNodo(x);//Límite de la funcion
  31.     }
  32.     else if (x<arbol->nro)
  33.     {
  34.         insertar(arbol->izq, x);
  35.     }
  36.     else if (x>arbol->nro)
  37.     {
  38.         insertar(arbol->der, x);
  39.     }
  40. }
  41. void imprimir(abb &arbol, int n);
  42.  
  43. int main()
  44. {
  45.     abb arbol = NULL; //Crear árbol
  46.     int n, x, opcion;
  47.     //Menú
  48.     do
  49.     {
  50.         system("color 4F");
  51.         system("cls");
  52.         cout << "Menu\n\t1. Ingresar datos al árbol\n\t2. Ver árbol (Horizontal)\n\3. Salir" << endl;
  53.  
  54.     } while (true);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement