From dfff9d01a44ce33f6a549dbae57d3c74c5849964 Mon Sep 17 00:00:00 2001 From: Enzo Fernandez Date: Fri, 9 May 2025 16:38:23 -0300 Subject: [PATCH 1/4] v1 decisionTree --- include/dataStructures/decisionTree.cpp | 127 ++++++++++++++++++++ include/dataStructures/decisionTree.hpp | 36 ++++++ include/dataStructures/testDecisionTree.cpp | 22 ++++ 3 files changed, 185 insertions(+) create mode 100644 include/dataStructures/decisionTree.cpp create mode 100644 include/dataStructures/decisionTree.hpp create mode 100644 include/dataStructures/testDecisionTree.cpp diff --git a/include/dataStructures/decisionTree.cpp b/include/dataStructures/decisionTree.cpp new file mode 100644 index 0000000..1f023ce --- /dev/null +++ b/include/dataStructures/decisionTree.cpp @@ -0,0 +1,127 @@ +#include "decisionTree.hpp" +#include +#include + +DecisionTree::DecisionTree() { + raiz = nullptr; +}; + +DecisionTree::~DecisionTree() { + destruir(raiz); +} + +void DecisionTree::destruir(Nodo* nodo) { + if (nodo == nullptr) return; + destruir(nodo->izquierda); + destruir(nodo->derecha); + delete nodo; +} + + +void DecisionTree::insertar(const std::string& decision) { + insertar(raiz, decision); +} + +void DecisionTree::insertar(Nodo*& nodo, const std::string& decision) { + if (nodo == nullptr) { + nodo = new Nodo(decision); + return; + } + + if (decision < nodo->decision) { + insertar(nodo->izquierda, decision); + } else { + insertar(nodo->derecha, decision); + } +} + + +bool DecisionTree::buscar(const std::string& decision) const +{ + //USO BFS PARA LA BUSQUEDA + if (raiz == nullptr) { + std::cout << "El árbol está vacío\n"; + return false; + } + + std::queue frontier; + frontier.push(raiz); + + while (!frontier.empty()) { + Nodo* actual = frontier.front(); + frontier.pop(); + + if (actual->decision == decision) { + return true; + } + + if (actual->izquierda != nullptr) { + frontier.push(actual->izquierda); + } + if (actual->derecha != nullptr) { + frontier.push(actual->derecha); + } + } + + return false; + +}; + +void DecisionTree::eliminar(const std::string& decision){ + //USO BFS PARA LA BUSQUEDA + if (raiz == nullptr) { + std::cout << "El árbol está vacío\n"; + return; + } + + std::queue frontier; + frontier.push(raiz); + + while (!frontier.empty()) { + Nodo* actual = frontier.front(); + frontier.pop(); + + if (actual->decision == decision) { + actual->decision = ""; + return; + } + + if (actual->izquierda != nullptr) { + frontier.push(actual->izquierda); + } + if (actual->derecha != nullptr) { + frontier.push(actual->derecha); + } + } + + return; +}; + +bool DecisionTree::estaVacio() const +{ + if(raiz == nullptr) + { + return true; + } + return false; +}; + +void DecisionTree::recorrerPreorden(Nodo* nodo) const +{ + if(nodo == nullptr) + { + return; + } + + std::cout<< nodo->decision; + recorrerPreorden(nodo->izquierda); + recorrerPreorden(nodo->derecha); +}; + +void DecisionTree::recorrerPreorden() const +{ + recorrerPreorden(raiz); +}; + + + diff --git a/include/dataStructures/decisionTree.hpp b/include/dataStructures/decisionTree.hpp new file mode 100644 index 0000000..e811d32 --- /dev/null +++ b/include/dataStructures/decisionTree.hpp @@ -0,0 +1,36 @@ +#include +struct Nodo { + std::string decision; + Nodo* izquierda; + Nodo* derecha; + + Nodo(const std::string& d) + : decision(d), izquierda(nullptr), derecha(nullptr) {} + }; + +#ifndef DECISIONTREE_HPP +#define DECISIONTREE_HPP + +class DecisionTree { + public: + + DecisionTree(); + ~DecisionTree(); + + void insertar(const std::string& decision); + bool buscar(const std::string& decision) const; + void eliminar(const std::string& decision); + bool estaVacio() const; + void recorrerPreorden() const; + + private: + Nodo* raiz; + + void insertar(Nodo*& nodo, const std::string& decision); + bool buscar(Nodo* nodo, const std::string& decision) const; + void eliminarNodo(Nodo*& nodo, const std::string& decision); + void recorrerPreorden(Nodo* nodo) const; + void destruir(Nodo* nodo); + }; + +#endif \ No newline at end of file diff --git a/include/dataStructures/testDecisionTree.cpp b/include/dataStructures/testDecisionTree.cpp new file mode 100644 index 0000000..5769ee7 --- /dev/null +++ b/include/dataStructures/testDecisionTree.cpp @@ -0,0 +1,22 @@ +#include +#include "decisionTree.hpp" + +int main() { + DecisionTree arbol; + arbol.insertar("Ajo"); + arbol.insertar("Berenjena"); + arbol.insertar("Calabaza"); + arbol.insertar("Calabazin"); + arbol.insertar("Tomate"); + + std::cout << "Buscar: " << arbol.buscar("Tomate") << "\n"; + + std::cout << "Recorrido :\n"; + arbol.recorrerPreorden(); + + arbol.eliminar("Tomate"); + std::cout << "Elimino Tomate\n"; + arbol.recorrerPreorden(); + + return 0; +} From eeda01911e72eb8ab639e98220122f7c14864252 Mon Sep 17 00:00:00 2001 From: Enzo Fernandez Date: Sun, 11 May 2025 16:54:41 -0300 Subject: [PATCH 2/4] v1.1 cambio de raiz por m_root --- include/dataStructures/decisionTree.cpp | 31 +++++++++++++------------ include/dataStructures/decisionTree.hpp | 2 +- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/include/dataStructures/decisionTree.cpp b/include/dataStructures/decisionTree.cpp index 1f023ce..e7f9231 100644 --- a/include/dataStructures/decisionTree.cpp +++ b/include/dataStructures/decisionTree.cpp @@ -3,11 +3,12 @@ #include DecisionTree::DecisionTree() { - raiz = nullptr; -}; + m_root = nullptr; +} DecisionTree::~DecisionTree() { - destruir(raiz); + destruir(m_root); + m_root = nullptr; } void DecisionTree::destruir(Nodo* nodo) { @@ -19,7 +20,7 @@ void DecisionTree::destruir(Nodo* nodo) { void DecisionTree::insertar(const std::string& decision) { - insertar(raiz, decision); + insertar(m_root, decision); } void DecisionTree::insertar(Nodo*& nodo, const std::string& decision) { @@ -39,13 +40,13 @@ void DecisionTree::insertar(Nodo*& nodo, const std::string& decision) { bool DecisionTree::buscar(const std::string& decision) const { //USO BFS PARA LA BUSQUEDA - if (raiz == nullptr) { + if (m_root == nullptr) { std::cout << "El árbol está vacío\n"; return false; } std::queue frontier; - frontier.push(raiz); + frontier.push(m_root); while (!frontier.empty()) { Nodo* actual = frontier.front(); @@ -65,17 +66,17 @@ bool DecisionTree::buscar(const std::string& decision) const return false; -}; +} void DecisionTree::eliminar(const std::string& decision){ //USO BFS PARA LA BUSQUEDA - if (raiz == nullptr) { + if (m_root == nullptr) { std::cout << "El árbol está vacío\n"; return; } std::queue frontier; - frontier.push(raiz); + frontier.push(m_root); while (!frontier.empty()) { Nodo* actual = frontier.front(); @@ -95,16 +96,16 @@ void DecisionTree::eliminar(const std::string& decision){ } return; -}; +} bool DecisionTree::estaVacio() const { - if(raiz == nullptr) + if(m_root == nullptr) { return true; } return false; -}; +} void DecisionTree::recorrerPreorden(Nodo* nodo) const { @@ -116,12 +117,12 @@ void DecisionTree::recorrerPreorden(Nodo* nodo) const std::cout<< nodo->decision; recorrerPreorden(nodo->izquierda); recorrerPreorden(nodo->derecha); -}; +} void DecisionTree::recorrerPreorden() const { - recorrerPreorden(raiz); -}; + recorrerPreorden(m_root); +} diff --git a/include/dataStructures/decisionTree.hpp b/include/dataStructures/decisionTree.hpp index e811d32..86da56e 100644 --- a/include/dataStructures/decisionTree.hpp +++ b/include/dataStructures/decisionTree.hpp @@ -24,7 +24,7 @@ class DecisionTree { void recorrerPreorden() const; private: - Nodo* raiz; + Nodo* m_root; void insertar(Nodo*& nodo, const std::string& decision); bool buscar(Nodo* nodo, const std::string& decision) const; From e4bb4884d0f341a076f7cd3e5ff3372fb9368a2c Mon Sep 17 00:00:00 2001 From: Enzo Fernandez Date: Mon, 19 May 2025 21:56:14 -0300 Subject: [PATCH 3/4] AVLTree --- assets/help.txt | 59 ------- assets/system.conf | 41 ----- include/dataStructures/avlTree.cpp | 212 ++++++++++++++++++++++++ include/dataStructures/avlTree.hpp | 46 +++++ include/dataStructures/decisionTree.cpp | 1 + 5 files changed, 259 insertions(+), 100 deletions(-) delete mode 100644 assets/help.txt delete mode 100644 assets/system.conf create mode 100644 include/dataStructures/avlTree.cpp create mode 100644 include/dataStructures/avlTree.hpp diff --git a/assets/help.txt b/assets/help.txt deleted file mode 100644 index c47eae8..0000000 --- a/assets/help.txt +++ /dev/null @@ -1,59 +0,0 @@ -==== MANUAL DEL INGENIERO DEL SISTEMA ==== - -Bienvenido al terminal de gestión del Refugio 33. -Este sistema ha sido desarrollado por VAULT-TEC para asistir al líder del refugio en la administración -de recursos, moradores, exploraciones, relaciones diplomáticas y defensa frente a amenazas externas. - -⚠️ ADVERTENCIA: Toda modificación en los subsistemas puede alterar el delicado equilibrio del refugio. -Y las baterías pueden verse afectadas... o no... o sí... depende. - -==== MODO DE USO ==== - -Comandos disponibles en la consola: - -- status : Muestra el estado actual del refugio (nombre, defensa, ataque, recursos y moradores). -- events : Lista los eventos registrados que han afectado al refugio. -- check : Verifica si hay eventos pendientes que requieren atención inmediata. -- explore : Simula una exploración exterior (puede derivar en descubrimientos... o peligros). -- fight : Simula un enfrentamiento con fuerzas hostiles (riesgo de bajas elevadas). -- save : Guarda el estado actual del sistema en los servidores cuánticos de VAULT. -- exit : Cierra la sesión del terminal y bloquea el acceso hasta nuevo ingreso. - -==== ARCHIVO DE RESPALDO ==== - -El sistema utiliza un archivo llamado `save.txt` ubicado en la carpeta `assets/` para almacenar -el estado completo del refugio, incluyendo configuraciones, eventos y datos del jugador. - -📌 Si el archivo NO existe, el sistema solicitará al usuario la siguiente información para iniciar una nueva sesión: - -- Nombre del Refugio -- Nombre del Líder - -Una vez ingresados, se generará automáticamente un respaldo y se activará el sistema con configuraciones predeterminadas. -Estas pueden personalizarse modificando el archivo `system.conf`. - -⚠️ Los ingenieros de VAULT-TEC no se responsabilizan por la edición manual de este archivo y sus posibles consecuencias. - -Sugerencia: guarde su progreso regularmente con el comando `save`. - -==== FACCIONES ==== - -- WATER_MERCHANTS : Controlan las reservas de agua. Intercambian por recursos a precios moderados. -- MERCHANTS : Comercian todo tipo de recursos (excepto agua). Más comunes que los anteriores. -- REFUGEES : Pertenecen a un refugio. Aumentan la defensa y ataque. Requieren recursos o se marchan. -- LOOTERS : Saqueadores oportunistas. Pueden ser agresivos o sigilosos. Grupos de 5 a 10 miembros. -- STEEL_BROTHERS : Orden militar-tecnológica. Usan artefactos únicos. Requieren el doble de recursos o se marchan. -- ENCLAVE : Fuerza militar de élite. Grupos de entre 10 y 50. Extremadamente letales. -- MUTANTS : Enemigos poderosos. Suelen aparecer en pares. ¡Evitar o eliminar! -- RAIDERS : Asaltantes armados. Grupos de 10 a 15. Pueden rendirse y unirse al refugio. -- GHOULS : Mutantes desfigurados. Atacan en hordas de hasta 100. Débiles pero numerosos. -- CARAVAN : Comerciantes de artefactos únicos. Precios extremadamente elevados. - -==== RECORDATORIO FINAL ==== - -Recuerde: el futuro del refugio depende de usted. Tome decisiones estratégicas, conserve los recursos y... ¡siga sonriendo! - -========================================== - Sistema de Control Refugio 33 – Vault-Tec - Versión de consola: 0.1.0 -========================================== diff --git a/assets/system.conf b/assets/system.conf deleted file mode 100644 index 587e774..0000000 --- a/assets/system.conf +++ /dev/null @@ -1,41 +0,0 @@ -# === CONFIGURACIÓN DEL SISTEMA REFUGIO 33 === -# Este archivo define los parámetros de eventos, exploración y combates -# ¡Modifique bajo su propia responsabilidad! - -[exploration] -successRate=0.45 ; Probabilidad de éxito al explorar (0.0 - 1.0) -lootChance=0.30 ; Posibilidad de encontrar recursos -dangerChance=0.25 ; Riesgo de evento hostil - -[fight] -criticalHitChance=0.15 ; Probabilidad de golpe crítico (0.0 - 1.0) -criticalHitMultiplier=2.0 ; Multiplicador de daño por golpe crítico -enemyAttackMultiplier=1.5 ; Multiplicador de ataque enemigo -enemyDefenseMultiplier=1.2 ; Multiplicador de defensa enemigo -enemyHealthMultiplier=1.3 ; Multiplicador de salud enemigo -enemyLootMultiplier=1.5 ; Multiplicador de botín enemigo -enemyExperienceMultiplier=1.5 ; Multiplicador de experiencia enemigo -luckyFactor=1.2 ; Factor de suerte para el jugador -minEnemy=1 ; Cantidad minima de enemigos -maxEnemy=4 ; Cantidad maxima de enemigos -surrenderChance=0.10 ; Chances de que se rinda un grupo de asaltantes - -[resources] -successRate=0.50 ; Probabilidad de éxito al recolectar recursos (0.0 - 1.0) -lootChance=0.40 ; Posibilidad de encontrar recursos -badLuckChance=0.20 ; Probabilidad de mala suerte al recolectar -durationFactor=1.5 ; Factor de duración de la recolección - -[shelter] -defenseFactor=1; Factor de defensa del refugio -attackFactor=1; Factor de ataque del refugio - -[events] -eventsPerSecond=1; Cantidad de eventor por segundo -rateRefugee=0.10; Tasa de visitantes del tipo refugiado -rateBrother=0.05; Tasa de visitantes del tipo hermanos -rateEnemy=0.50; Tasa de visitantes del tipo enemigo -rateCommerce=0.70; Tasa de visitantes del tipo comerciantes -rateCaravane=0.02; Tasa de visitantes del tipo caravana - -# === FIN DEL ARCHIVO === diff --git a/include/dataStructures/avlTree.cpp b/include/dataStructures/avlTree.cpp new file mode 100644 index 0000000..6d4a04c --- /dev/null +++ b/include/dataStructures/avlTree.cpp @@ -0,0 +1,212 @@ +#include "avlTree.hpp" +#include + +int AVLTree::getHeight(Node* node) { + if(node == NULL) + return -1; + return std::max(getHeight(node->l),getHeight(node->r)) +1; +} + +int AVLTree::getBalance(Node* node){ + if(node == NULL) + return -1; + return getHeight(node->l) - getHeight(node->r); +} + +void AVLTree::actHeight(Node* n){ + if (n==nullptr) { + return; + } + n->height = 1 + std::max(getHeight(n->l), getHeight(n->r)); +} + +Node* AVLTree::rightRotation(Node* node){ + Node* rot = node->l; + Node* T2 = rot->r; + + rot->r = node; + node->l = T2; + + actHeight(rot); + actHeight(node); + + return rot; + +} + +Node* AVLTree::leftRotation(Node* node){ + Node* rot = node->r; + Node* T2 = rot->l; + + rot->l = node; + node->r = T2; + + actHeight(rot); + actHeight(node); + + return rot; +} + +Node* AVLTree::insert(Node* nodo, int outpostId, int priority){ + if(nodo == NULL) return new Node(outpostId,priority); + + if(priority <= nodo->priority) + nodo->l = insert(nodo->l,outpostId,priority); + else if(priority > nodo->priority) + nodo->r = insert(nodo->r,outpostId,priority); + else + return nodo; + + actHeight(nodo); + + int b = getBalance(nodo); + + if (b > 1 && priority < nodo->l->priority) + return rightRotation(nodo); + + if (b < -1 && priority > nodo->r->priority) + return leftRotation(nodo); + + if (b > 1 && priority > nodo->l->priority) { + nodo->l = leftRotation(nodo->l); + return rightRotation(nodo); + } + + if (b < -1 && priority < nodo->r->priority) { + nodo->r = rightRotation(nodo->r); + return leftRotation(nodo); + } + + return nodo; + +} + +int AVLTree::findMin(Node* node){ + if(node == NULL) + return -1; + + else if(node->l == NULL) + return node->outpostId; + + return findMin(node->l); +} + +Node* AVLTree::findMinNode(Node* node){ + if(node == NULL) + return; + + else if(node->l == NULL) + return node; + + return findMinNode(node->l); +} + +int AVLTree::findMax(Node* node){ + if(node == NULL) + return -1; + + else if(node->r == NULL) + return node->outpostId; + + return findMin(node->r); +} + +bool AVLTree::contains(int outpostId){ + + if(m_root == NULL){ + std::cout<<"Arbol vacio"<<"\n"; + return false; + } + + std::queue frontier; + frontier.push(m_root); + + while(!frontier.empty()) + { + Node* temp = frontier.front(); + frontier.pop(); + + if(temp->outpostId == outpostId) + return true; + + if(temp->l != NULL) + frontier.push(temp->l); + if(temp->r != NULL) + frontier.push(temp->r); + } + return false; + +} + +void AVLTree::LRD(Node* node){ + if (node == NULL) + return; + + LRD(node->l); // + std::cout << node->outpostId << " - "; + LRD(node->r); + +} + +void AVLTree::printInOrder(){ + + LRD(m_root); +} + +int AVLTree::countNodes(Node* node) { + if (node == nullptr) return 0; + return 1 + countNodes(node->l) + countNodes(node->r); +} + +void AVLTree::printStats(){ + int totalNodos = countNodes(m_root); + int altura = getHeight(m_root); + + std::cout << "Cantidad de nodos: " << totalNodos << "\n"; + std::cout << "Altura del árbol: " << altura << "\n"; + +} + +Node* AVLTree::remove(Node* nodo, int outpostId){ + + std::queue frontier; + frontier.push(nodo); + + while(!frontier.empty()) + { + if(nodo->outpostId == outpostId) + { + + if(nodo->l == NULL && nodo->r == NULL) + delete nodo; + else if(nodo->l == NULL) + { + Node* temp = nodo; + nodo = nodo->r; + delete temp; + } + else if(nodo->r == NULL) + { + Node* temp = nodo; + nodo = nodo->r; + delete temp; + } + else + { + Node* temp = findMinNode(nodo->r); + nodo->outpostId = temp->outpostId; + nodo->priority = temp->priority; + nodo->r = remove(nodo->r, temp->outpostId); + + } + + + } + if(nodo->l != NULL) + frontier.push(nodo->l); + if(nodo->r != NULL) + frontier.push(nodo->r); + } + + +} \ No newline at end of file diff --git a/include/dataStructures/avlTree.hpp b/include/dataStructures/avlTree.hpp new file mode 100644 index 0000000..47b00e3 --- /dev/null +++ b/include/dataStructures/avlTree.hpp @@ -0,0 +1,46 @@ +#include + +struct Node { + int outpostId; + int priority; + int height; + Node* l; + Node* r; + Node(int id, int p) : outpostId(id), priority(p), height(0), l(nullptr), r(nullptr) {} +}; + +#ifndef AVLTREE_HPP +#define AVLTREE_HPP + +class AVLTree { + private: + Node* m_root; + int getHeight(Node* node); // + int getBalance(Node* node);// + Node* rightRotation(Node* node);// + Node* leftRotation(Node* node);// + void actHeight(Node* n);// + Node* insert(Node* nodo, int outpostId, int priority);// + Node* remove(Node* nodo,int outpostId); // + int findMin(Node* node);// + int findMax(Node* node);// + void LRD(Node* node); // + int countNodes(Node* node);// + Node* AVLTree::findMinNode(Node* node);// + void destruir(Node* node); + + public: + AVLTree(); + ~AVLTree(); + void insert(int outpostId, int priority); // + void remove(int outpostId); + bool contains(int outpostId); // + int findMin();// + int findMax();// + void printInOrder(); // + void printStats(); // + + +}; + +#endif \ No newline at end of file diff --git a/include/dataStructures/decisionTree.cpp b/include/dataStructures/decisionTree.cpp index e7f9231..c42e283 100644 --- a/include/dataStructures/decisionTree.cpp +++ b/include/dataStructures/decisionTree.cpp @@ -16,6 +16,7 @@ void DecisionTree::destruir(Nodo* nodo) { destruir(nodo->izquierda); destruir(nodo->derecha); delete nodo; + } From 243d20d304f7376ef9f2f62314c856a6187651e9 Mon Sep 17 00:00:00 2001 From: Enzo Fernandez Date: Mon, 19 May 2025 22:02:29 -0300 Subject: [PATCH 4/4] AVLTree1 --- .gitignore | Bin 304 -> 360 bytes .vscode/settings.json | 66 ++++++++++++++++++ assets/help.txt | 0 assets/system.conf | 41 ++++++++++++ include/dataStructures/avlTree.cpp | 103 +++++++++++++++++++---------- 5 files changed, 175 insertions(+), 35 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 assets/help.txt create mode 100644 assets/system.conf diff --git a/.gitignore b/.gitignore index 17a4914034eba261d893994de6de52ca99777b8c..7960b5e391fcb7ff67f1077d79973df47b61b7b1 100644 GIT binary patch literal 360 zcmZ8cOKw6j4D>ou?huJxCEyUHRd=n_6F9MC|vlb z#~K?~Yo0b_jWsLxoToV^Cim`-9Gcq?qW3jrku6h?*&i3r$O<>x8zXU1$02-)V-|Rb z-d#>O#o$u(1xviDU@7_~jh)S>T) z@8!&)H}uzk@|i`GdsFE=ON}t$H?Mt literal 304 zcmZ9HOAf*?3`F-iMI?4eZ4bdm>_FlKPGX9S+mtks;P%+9KoyIOV|(T)+1N|MgwH|~ zWt_~m4#sTkF7_ia277iL`fP8~=yKvHI*VSS>(ng>{|%fF0w(pg{w_L-u7Uga06lrj zXSyQhW@*k9e#K|C{N8yqr == NULL) return node->outpostId; - return findMin(node->r); + return findMax(node->r); } bool AVLTree::contains(int outpostId){ @@ -167,46 +167,79 @@ void AVLTree::printStats(){ } -Node* AVLTree::remove(Node* nodo, int outpostId){ - std::queue frontier; - frontier.push(nodo); - while(!frontier.empty()) - { - if(nodo->outpostId == outpostId) - { - - if(nodo->l == NULL && nodo->r == NULL) - delete nodo; - else if(nodo->l == NULL) - { - Node* temp = nodo; - nodo = nodo->r; - delete temp; - } - else if(nodo->r == NULL) - { - Node* temp = nodo; - nodo = nodo->r; - delete temp; - } - else - { - Node* temp = findMinNode(nodo->r); - nodo->outpostId = temp->outpostId; - nodo->priority = temp->priority; - nodo->r = remove(nodo->r, temp->outpostId); - - } +Node* AVLTree::remove(Node* nodo, int outpostId) { + if (nodo == nullptr) return nullptr; + if (nodo->outpostId == outpostId) { + if (nodo->l == nullptr && nodo->r == nullptr) { + delete nodo; + return nullptr; } - if(nodo->l != NULL) - frontier.push(nodo->l); - if(nodo->r != NULL) - frontier.push(nodo->r); + + if (nodo->l == nullptr) { + Node* temp = nodo->r; + delete nodo; + return temp; + } + if (nodo->r == nullptr) { + Node* temp = nodo->l; + delete nodo; + return temp; + } + + Node* temp = findMinNode(nodo->r); + nodo->outpostId = temp->outpostId; + nodo->priority = temp->priority; + nodo->r = remove(nodo->r, temp->outpostId); + } else { + + nodo->l = remove(nodo->l, outpostId); + nodo->r = remove(nodo->r, outpostId); + } + + actHeight(nodo); + int bf = getBalance(nodo); + + if (bf > 1 && getBalance(nodo->l) >= 0) + return rightRotation(nodo); + if (bf > 1 && getBalance(nodo->l) < 0) { + nodo->l = leftRotation(nodo->l); + return rightRotation(nodo); } + if (bf < -1 && getBalance(nodo->r) <= 0) + return leftRotation(nodo); + if (bf < -1 && getBalance(nodo->r) > 0) { + nodo->r = rightRotation(nodo->r); + return leftRotation(nodo); + } + + return nodo; +} + +void AVLTree::remove(int outpostId){ + remove(m_root,outpostId); + return; +} +void AVLTree::insert(int outpostId, int priority) +{ + insert(m_root,outpostId,priority); + return; +} + +AVLTree::AVLTree() : m_root(nullptr) {} + +void AVLTree::destruir(Node* node) { + if (!node) return; + destruir(node->l); + destruir(node->r); + delete node; +} +AVLTree::~AVLTree() { + destruir(m_root); + m_root = nullptr; } \ No newline at end of file