diff --git a/README.md b/README.md index 80b912b..702b933 100644 --- a/README.md +++ b/README.md @@ -25,17 +25,17 @@ The representation of the avl tree in this application is only to save integers, As [freecodecamp](https://www.freecodecamp.org/news/avl-tree-insertion-rotation-and-balance-factor/) describes, a search binary tree is a TDA composed of nodes that have the following rules: -1. Each has a root node at the top. + 1. Each has a root node at the top. -2. Every node has at the most, two children. + 2. Every node has at the most, two children. -3. Every node has only one parent (the root is the one node that has no parents). + 3. Every node has only one parent (the root is the one node that has no parents). -4. For each node, its left child is less or equal than the node, wich is less or equal than its right child. + 4. For each node, its left child is less or equal than the node, wich is less or equal than its right child. And the Avl tree has additionally this rule: -1.- The difference between the depth of right and left subtrees cannot be more than one. In order to maintain this guarantee, an implementation of an AVL will include an algorithm to rebalance the tree when adding an additional element would upset this guarantee. + 1. The difference between the depth of right and left subtrees cannot be more than one. In order to maintain this guarantee, an implementation of an AVL will include an algorithm to rebalance the tree when adding an additional element would upset this guarantee. There are several algotihm to aim that, a few of these are: LL rotation, RR rotation, LR rotation and RL rotation, you can watch all these algorithsm to balance the tree in this [video](https://www.youtube.com/watch?v=7m94k2Qhg68). @@ -67,7 +67,7 @@ java -jar dist/Avl-Tree.jar [language-shield]: https://img.shields.io/badge/Java-v1.8.0-blue?style=plastic [language-url]: https://www.java.com/es/download/ -[codacybadge-shield]: https://img.shields.io/codacy/grade/3c17ebf7c1954006a60b08b8af2c58e2?style=plastic +[codacybadge-shield]: https://img.shields.io/codacy/grade/4514b80a741147ba9cf70541aca4a806?style=plastic [codacybadge-url]: https://www.codacy.com/manual/AlexVelezLl/AVL-TREE?utm_source=github.com&utm_medium=referral&utm_content=AlexVelezLl/AVL-TREE&utm_campaign=Badge_Grade [repoSize-shield]: https://img.shields.io/github/repo-size/AlexVelezLl/AVL-TREE?style=plastic [repo]: https://github.com/AlexVelezLl/AVL-TREE diff --git a/src/Interfaz/InterfazArbol.java b/src/Interfaz/InterfazArbol.java index 413fec5..7ae29fb 100644 --- a/src/Interfaz/InterfazArbol.java +++ b/src/Interfaz/InterfazArbol.java @@ -26,7 +26,7 @@ /** * - * @author CORE i7 ULTIMATE + * @author AlexVelezLl */ public class InterfazArbol { private Pane root; @@ -34,7 +34,7 @@ public class InterfazArbol { private ScrollPane sp; private final TextField txtInsertar; private final TextField txtDelete; - StackPane arbol; + private StackPane arbol; public InterfazArbol() { root = new VBox(); diff --git a/src/tda/AVL.java b/src/tda/AVL.java index e1adfa9..2830d31 100644 --- a/src/tda/AVL.java +++ b/src/tda/AVL.java @@ -485,7 +485,10 @@ private boolean idexOutOfBoundsException(final Pane vb, final int n) { // EX remove public boolean delete(final Object o) throws ClassCastException, NullPointerException { - Nodo borrar = null, mirar = null, cambiar = null, nPadre = null; + Nodo borrar = null; + Nodo mirar = null; + Nodo cambiar = null; + Nodo nPadre = null; Nodo raizTmp = this.getRoot(); E c_aux; boolean salir = false; @@ -596,6 +599,7 @@ else if (borrar.getRight() != null) { cambiar.setData(cambiar.getRight().getData()); cambiar.setRight(null); } + borrar.setData(c_aux); } else { diff --git a/test/tda/AVLTest.java b/test/tda/AVLTest.java deleted file mode 100644 index 4865d32..0000000 --- a/test/tda/AVLTest.java +++ /dev/null @@ -1,397 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package tda; - -import javafx.scene.layout.Pane; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * - * @author ktiusk - */ -public class AVLTest { - - @BeforeClass - public static void setUpClass() { - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - /** - * Test of getRoot method, of class AVL. - */ - @Test - public void testGetRoot() { - System.out.println("getRoot"); - AVL instance = null; - Nodo expResult = null; - Nodo result = instance.getRoot(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of setRoot method, of class AVL. - */ - @Test - public void testSetRoot() { - System.out.println("setRoot"); - AVL instance = null; - instance.setRoot(null); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of isEmpty method, of class AVL. - */ - @Test - public void testIsEmpty() { - System.out.println("isEmpty"); - AVL instance = null; - boolean expResult = false; - boolean result = instance.isEmpty(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of height method, of class AVL. - */ - @Test - public void testHeight() { - System.out.println("height"); - AVL instance = new AVL<>(Integer::compareTo); - instance.Insert(8); - instance.Insert(2); - int expResult = 2; - int result = instance.height(); - assertEquals(expResult, result); - if (result != expResult) - fail("The test case is a prototype."); - } - - /** - * Test of totalNodos method, of class AVL. - */ - @Test - public void testTotalNodos() { - System.out.println("totalNodos"); - AVL instance = new AVL<>(Integer::compareTo); - instance.Insert(8); - instance.Insert(2); - int expResult = 2; - int result = instance.totalNodos(); - assertEquals(expResult, result); - if (result != expResult) - fail("The test case is a prototype."); - } - - /** - * Test of contarHojas method, of class AVL. - */ - @Test - public void testContarHojas() { - System.out.println("contarHojas"); - AVL instance = new AVL<>(Integer::compareTo); - instance.Insert(8); - instance.Insert(2); - int expResult = 1; - int result = instance.contarHojas(); - assertEquals(expResult, result); - if (result != expResult) - fail("The test case is a prototype."); - } - - /** - * Test of add method, of class AVL. - */ - @Test - public void testAdd() { - System.out.println("add"); - Object element = null; - AVL instance = null; - boolean expResult = false; - boolean result = instance.add(element); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of Insert method, of class AVL. - */ - @Test - public void testInsert() { - System.out.println("Insert"); - Nodo element = null; - AVL instance = new AVL<>(Integer::compareTo); - instance.Insert(8); - instance.Insert(2); - boolean expResult = false; - boolean result = instance.Insert(element); - assertFalse(result); - // TODO review the generated test code and remove the default call to fail. - if (result != expResult) - fail("The test case is a prototype."); - } - - /** - * Test of deleteNode method, of class AVL. - */ - @Test - public void testDeleteNode() { - System.out.println("deleteNode"); - Object element = null; - AVL instance = null; - boolean expResult = false; - boolean result = instance.delete(element); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of esDegenerado method, of class AVL. - */ - @Test - public void testEsDegenerado() { - System.out.println("esDegenerado"); - AVL instance = null; - boolean expResult = false; - boolean result = instance.esDegenerado(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of calcularCarga method, of class AVL. - */ - @Test - public void testCalcularCarga() { - System.out.println("calcularCarga"); - AVL instance = new AVL<>(Integer::compareTo); - instance.Insert(8); - instance.Insert(2); - int expResult = -1; - int result = instance.calcularCarga(); - assertEquals(expResult, result); - if (result != expResult) - fail("The test case is a prototype."); - } - - /** - * Test of rotacionSimpleIzquierda method, of class AVL. - */ - @Test - public void testRotacionSimpleIzquierda() { - System.out.println("rotacionSimpleIzquierda"); - AVL instance = null; - Nodo expResult = null; - Nodo result = instance.rotacionSimpleIzquierda(null); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of rotacionSimpleDerecha method, of class AVL. - */ - @Test - public void testRotacionSimpleDerecha() { - System.out.println("rotacionSimpleDerecha"); - AVL instance = null; - Nodo expResult = null; - Nodo result = instance.rotacionSimpleDerecha(null); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of rotacionDobleIzquierda method, of class AVL. - */ - @Test - public void testRotacionDobleIzquierda() { - System.out.println("rotacionDobleIzquierda"); - AVL instance = null; - Nodo expResult = null; - Nodo result = instance.rotacionDobleIzquierda(null); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of rotacionDobleDerecha method, of class AVL. - */ - @Test - public void testRotacionDobleDerecha() { - System.out.println("rotacionDobleDerecha"); - AVL instance = null; - Nodo expResult = null; - Nodo result = instance.rotacionDobleDerecha(null); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of max method, of class AVL. - */ - @Test - public void testMax() { - System.out.println("max"); - AVL instance = null; - Object expResult = null; - Object result = instance.max(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of min method, of class AVL. - */ - @Test - public void testMin() { - System.out.println("min"); - AVL instance = null; - Object expResult = null; - Object result = instance.min(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of contains method, of class AVL. - */ - @Test - public void testContains() { - System.out.println("contains"); - Object element = null; - AVL instance = null; - boolean expResult = false; - boolean result = instance.contains(element); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of posOrde method, of class AVL. - */ - @Test - public void testPosOrde() { - System.out.println("posOrde"); - AVL instance = null; - instance.posOrde(); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of preOrden method, of class AVL. - */ - @Test - public void testPreOrden() { - System.out.println("preOrden"); - AVL instance = null; - instance.preOrden(); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of enOrden method, of class AVL. - */ - @Test - public void testEnOrden() { - System.out.println("enOrden"); - AVL instance = null; - instance.enOrden(); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of nivel method, of class AVL. - */ - @Test - public void testNivel() { - System.out.println("nivel"); - Object element = null; - AVL instance = null; - int expResult = 0; - int result = instance.nivel(element); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of equals method, of class AVL. - */ - @Test - public void testEquals() { - System.out.println("equals"); - Object obj = null; - AVL instance = null; - boolean expResult = false; - boolean result = instance.equals(obj); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of hashCode method, of class AVL. - */ - @Test - public void testHashCode() { - System.out.println("hashCode"); - AVL instance = null; - int expResult = 0; - int result = instance.hashCode(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of mostrarArbol method, of class AVL. - */ - @Test - public void testMostrarArbol() { - System.out.println("mostrarArbol"); - AVL instance = null; - Pane expResult = null; - Pane result = instance.mostrarArbol(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - -}