This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void preOrden(Nodo<T> *&nodo) | |
| { | |
| cout << nodo->dato << " : "; | |
| if (nodo->izquierda != NULL) | |
| { | |
| preOrden(nodo->izquierda); | |
| } | |
| if (nodo->derecha != NULL) | |
| { | |
| preOrden(nodo->derecha); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void postOrden() | |
| { | |
| postOrden(raiz); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void inOrden() | |
| { | |
| inOrden(raiz); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void preOrden() | |
| { | |
| preOrden(raiz); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void insertar(T dato) | |
| { | |
| if (raiz == NULL) | |
| { | |
| raiz = new Nodo<T>(dato); | |
| } | |
| else | |
| { | |
| insertar(raiz, dato); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void insertar(Nodo<T> *&nodo, T dato) | |
| { | |
| if (nodo == NULL) // Caso Base | |
| { | |
| nodo = new Nodo<T>(dato); | |
| } | |
| else // Caso recursivo | |
| { | |
| if (dato < nodo->dato) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bool buscar(Nodo<T> *&nodo, T dato) | |
| { | |
| if (nodo == NULL) // Caso base | |
| { | |
| cout << "No encontrado\n"; | |
| return false; | |
| } | |
| else if (dato == nodo->dato) // Caso base | |
| { | |
| cout << "Encontrado: " << nodo->dato << endl; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bool buscar(T dato) | |
| { | |
| if (raiz == NULL) | |
| { | |
| cout << "Not found\n"; | |
| return -1; | |
| } | |
| else | |
| { | |
| buscar(raiz, dato); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <typename T> | |
| class ArbolBinario | |
| { | |
| // Atributo raíz inicial del arbol | |
| private: | |
| Nodo<T> *raiz; | |
| // Constructor por default | |
| public: | |
| ArbolBinario() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <typename T> | |
| class Nodo | |
| { | |
| private: | |
| T dato; | |
| Nodo<T> *izquierda; | |
| Nodo<T> *derecha; | |
| template <typename U> | |
| friend class ArbolBinario; |