From 942606f8ac204250bcc5879b4b991adb6c2547b2 Mon Sep 17 00:00:00 2001 From: AlexVelezLl Date: Thu, 7 May 2020 22:11:26 -0500 Subject: [PATCH 1/3] Add gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..14bc68c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/nbproject/private/ \ No newline at end of file From 7810f59a6551e52d86468916d4aa5b876b3476dc Mon Sep 17 00:00:00 2001 From: AlexVelezLl Date: Thu, 7 May 2020 23:55:27 -0500 Subject: [PATCH 2/3] Removed inused imports and fix some peek problems --- src/Interfaz/InterfazArbol.java | 89 +++++++++++++++------------------ src/tda/AVL.java | 11 ++-- 2 files changed, 48 insertions(+), 52 deletions(-) diff --git a/src/Interfaz/InterfazArbol.java b/src/Interfaz/InterfazArbol.java index 19b28a3..77b3958 100644 --- a/src/Interfaz/InterfazArbol.java +++ b/src/Interfaz/InterfazArbol.java @@ -5,7 +5,6 @@ */ package Interfaz; -import java.util.ArrayList; import javafx.application.Platform; import javafx.geometry.Pos; import javafx.scene.control.Button; @@ -17,14 +16,8 @@ import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; -import javafx.scene.shape.Circle; -import javafx.scene.shape.LineTo; -import javafx.scene.shape.MoveTo; -import javafx.scene.shape.Path; -import javafx.scene.shape.PathElement; import javafx.scene.shape.Rectangle; import javafx.scene.text.Font; -import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; import tda.AVL; @@ -36,17 +29,17 @@ public class InterfazArbol { private Pane root; private AVL avlTree; private ScrollPane sp; - - public InterfazArbol(){ + + public InterfazArbol() { root = new VBox(); avlTree = new AVL<>(Integer::compareTo); sp = new ScrollPane(); - + createRoot(); } - - private void createRoot(){ - Rectangle topRect = new Rectangle(1366,75); + + private void createRoot() { + Rectangle topRect = new Rectangle(1366, 75); topRect.setFill(Color.DARKCYAN); Label lblAvl = new Label("AVL TREE"); lblAvl.setTranslateX(30); @@ -55,7 +48,7 @@ private void createRoot(){ lblAvl.setFont(theFont); lblAvl.setTextFill(Color.WHITE); Pane topPane = new Pane(); - topPane.getChildren().addAll(topRect,lblAvl); + topPane.getChildren().addAll(topRect, lblAvl); HBox hbOpc = new HBox(); hbOpc.setAlignment(Pos.CENTER); hbOpc.setTranslateY(6); @@ -64,88 +57,88 @@ private void createRoot(){ TextField txtDelete = new TextField(); Button btnDelete = new Button("Eliminar"); HBox hbInst = new HBox(); - hbInst.getChildren().addAll(txtInsertar,btnInsertar); + hbInst.getChildren().addAll(txtInsertar, btnInsertar); hbInst.setSpacing(5); HBox hbDel = new HBox(); - hbDel.getChildren().addAll(txtDelete,btnDelete); + hbDel.getChildren().addAll(txtDelete, btnDelete); hbDel.setSpacing(5); Button btnClear = new Button("Clear"); Pane pnClear = new Pane(btnClear); - hbOpc.getChildren().addAll(hbInst,hbDel,pnClear); + hbOpc.getChildren().addAll(hbInst, hbDel, pnClear); hbOpc.setSpacing(30); - Rectangle optRect = new Rectangle(1366,40); + Rectangle optRect = new Rectangle(1366, 40); optRect.setOpacity(0.7); optRect.setFill(Color.CADETBLUE); StackPane optStck = new StackPane(); - optStck.getChildren().addAll(optRect,hbOpc); + optStck.getChildren().addAll(optRect, hbOpc); StackPane arbol = new StackPane(); arbol.setMinHeight(200); arbol.setMinWidth(1366); - btnClear.setOnMouseClicked(e->{ + btnClear.setOnMouseClicked(e -> { avlTree = new AVL<>(Integer::compareTo); arbol.getChildren().clear(); Pane avlPane = avlTree.mostrarArbol(); arbol.getChildren().add(avlPane); - arbol.setMinWidth(avlTree.height()*100); + arbol.setMinWidth(avlTree.height() * 100); }); sp.setContent(arbol); sp.setMinHeight(500); sp.setMaxHeight(500); - btnInsertar.setOnAction(e->{ - Integer num=0; - try{ + btnInsertar.setOnAction(e -> { + Integer num = 0; + try { num = Integer.parseInt(txtInsertar.getText()); txtInsertar.setText(""); txtInsertar.requestFocus(); avlTree.Insert(num); - + arbol.getChildren().clear(); Pane avlPane = avlTree.mostrarArbol(); - if(avlTree.height()<=7) avlPane.setTranslateX(100*(7-avlTree.height())); + if (avlTree.height() <= 7) + avlPane.setTranslateX(100 * (7 - avlTree.height())); arbol.getChildren().add(avlPane); - arbol.setMinWidth(avlTree.height()*100); - }catch(Exception ex){ - + arbol.setMinWidth(avlTree.height() * 100); + } catch (Exception ex) { + } - + }); - - btnDelete.setOnMouseClicked(e->{ - Integer num=0; - try{ + + btnDelete.setOnMouseClicked(e -> { + Integer num = 0; + try { num = Integer.parseInt(txtDelete.getText()); txtDelete.setText(""); txtDelete.requestFocus(); avlTree.delete(num); arbol.getChildren().clear(); Pane avlPane = avlTree.mostrarArbol(); - if(avlTree.height()<=7) avlPane.setTranslateX(100*(7-avlTree.height())); + if (avlTree.height() <= 7) + avlPane.setTranslateX(100 * (7 - avlTree.height())); arbol.getChildren().add(avlPane); - arbol.setMinWidth(avlTree.height()*100); - - }catch(Exception ex){ - + arbol.setMinWidth(avlTree.height() * 100); + + } catch (Exception ex) { + } }); - - + StackPane pnSalir = new StackPane(); Label lblSalir = new Label("Salir"); lblSalir.setFont(Font.font("Arial", FontWeight.BOLD, 40)); lblSalir.setTextFill(Color.RED); pnSalir.getChildren().add(lblSalir); - pnSalir.setOnMouseClicked(e->{ + pnSalir.setOnMouseClicked(e -> { Platform.exit(); }); pnSalir.setTranslateY(30); pnSalir.setTranslateX(20); - - root.getChildren().addAll(topPane,optStck,sp,pnSalir); - + + root.getChildren().addAll(topPane, optStck, sp, pnSalir); + } - - - public Pane getRoot(){ + + public Pane getRoot() { return root; } } diff --git a/src/tda/AVL.java b/src/tda/AVL.java index 0da858b..2667235 100644 --- a/src/tda/AVL.java +++ b/src/tda/AVL.java @@ -389,10 +389,11 @@ public boolean equals(Object obj) { else if (!(this instanceof AVL) || !(obj instanceof AVL)){ return false; } + @SuppressWarnings("unchecked") final AVL other = (AVL) obj; return equals(this.root,other.root); } - private boolean equals(Nodo n1, Nodo n2){ + private boolean equals(Nodo n1, Nodo n2){ if(n1 == null && n2 == null) return true; else if((n1 == null && n2 != null) || (n1 != null && n2 == null)) @@ -502,7 +503,7 @@ private boolean idexOutOfBoundsException(Pane vb, int n){ public boolean delete(Object o) throws ClassCastException, NullPointerException{ Nodo borrar=null,mirar=null,cambiar=null, nPadre = null; Nodo raizTmp = this.getRoot(); - E c_aux, d_aux; + E c_aux; boolean salir = false; int altDer = 0; int altIzq = 0; @@ -512,7 +513,8 @@ public boolean delete(Object o) throws ClassCastException, NullPointerException{ return false; } - //el nodo a borrar es la raiz? + + //el nodo a borrar es la raiz? if(this.compararDato((E)o, raizTmp.getData())==0){ salir = true; borrar = raizTmp; @@ -679,7 +681,8 @@ public Nodo padre(Nodo nodo){ else if(this.compararDato(nodo.getData(), raizTmp.getData())<0){ if(raizTmp.getLeft()!=null){ raizTmp = raizTmp.getLeft(); - } + } + } if(this.compararDato(nodo.getData(), raizTmp.getData())==0){ return pila.pop(); From ffa0af18d4d0fdb126d1fadca870bafeeff297c3 Mon Sep 17 00:00:00 2001 From: AlexVelezLl Date: Tue, 12 May 2020 10:50:02 -0500 Subject: [PATCH 3/3] Fix Issues --- src/Interfaz/Index.java | 12 +- src/Interfaz/InterfazArbol.java | 6 +- src/tda/AVL.java | 1200 +++++++++++++++---------------- src/tda/Nodo.java | 69 +- test/tda/AVLTest.java | 23 +- 5 files changed, 644 insertions(+), 666 deletions(-) diff --git a/src/Interfaz/Index.java b/src/Interfaz/Index.java index 03a4189..5ef8149 100644 --- a/src/Interfaz/Index.java +++ b/src/Interfaz/Index.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package Interfaz; +package interfaz; import javafx.application.Application; import javafx.scene.Scene; @@ -11,21 +11,21 @@ /** * - * @author CORE i7 ULTIMATE + * @author AlexVelezLl */ -public class Index extends Application{ - public static void main(String [] args){ +public class Index extends Application { + public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { InterfazArbol ia = new InterfazArbol(); - Scene sc = new Scene(ia.getRoot(),1366,768); + Scene sc = new Scene(ia.getRoot(), 1366, 768); primaryStage.setScene(sc); primaryStage.setFullScreen(true); primaryStage.setResizable(false); primaryStage.show(); - + } } diff --git a/src/Interfaz/InterfazArbol.java b/src/Interfaz/InterfazArbol.java index 77b3958..9c76040 100644 --- a/src/Interfaz/InterfazArbol.java +++ b/src/Interfaz/InterfazArbol.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package Interfaz; +package interfaz; import javafx.application.Platform; import javafx.geometry.Pos; @@ -34,7 +34,6 @@ public InterfazArbol() { root = new VBox(); avlTree = new AVL<>(Integer::compareTo); sp = new ScrollPane(); - createRoot(); } @@ -74,6 +73,7 @@ private void createRoot() { StackPane arbol = new StackPane(); arbol.setMinHeight(200); arbol.setMinWidth(1366); + arbol.setMinWidth(avlTree.height() * 100); btnClear.setOnMouseClicked(e -> { avlTree = new AVL<>(Integer::compareTo); arbol.getChildren().clear(); @@ -90,7 +90,7 @@ private void createRoot() { num = Integer.parseInt(txtInsertar.getText()); txtInsertar.setText(""); txtInsertar.requestFocus(); - avlTree.Insert(num); + avlTree.insert(num); arbol.getChildren().clear(); Pane avlPane = avlTree.mostrarArbol(); diff --git a/src/tda/AVL.java b/src/tda/AVL.java index 2667235..e1adfa9 100644 --- a/src/tda/AVL.java +++ b/src/tda/AVL.java @@ -4,6 +4,7 @@ * and open the template in the editor. */ package tda; + import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -21,804 +22,783 @@ /** * Árbol binario de búsqueda, los elementos mayores estan a la derecha, + * * @author kmmarin */ -public class AVL { //AVL - +public class AVL { // AVL + private Nodo root; - private Comparator f; - - public AVL(Comparator f) { + private final Comparator f; + + public AVL(final Comparator f) { this.f = f; - this.root=null; + this.root = null; } public Nodo getRoot() { return root; } - public void setRoot(Nodo root) { + public void setRoot(final Nodo root) { this.root = root; } - - public boolean isEmpty(){ - return root==null; + + public boolean isEmpty() { + return root == null; } - - public int height(){ + + public int height() { return height(root); } - + /** * Calcula la altura de un nodo + * * @param n * @return int */ - private int height(Nodo n){ - if(n == null) + private int height(final Nodo n) { + if (n == null) return 0; - return 1+ Math.max(height(n.getLeft()),height(n.getRight())); + return 1 + Math.max(height(n.getLeft()), height(n.getRight())); } - - public int totalNodos(){ + + public int totalNodos() { return totalNodos(root); } - - private int totalNodos(Nodo n){ - if (n==null) + + private int totalNodos(final Nodo n) { + if (n == null) return 0; - return 1 + totalNodos(n.getLeft())+ totalNodos(n.getRight()); + return 1 + totalNodos(n.getLeft()) + totalNodos(n.getRight()); } - - public int contarHojas(){ + + public int contarHojas() { return contarHojas(root); } - private int contarHojas(Nodo n){ - if(n==null) + + private int contarHojas(final Nodo n) { + if (n == null) return 0; - else if(n.getLeft()==null&& n.getRight()==null){ + else if (n.getLeft() == null && n.getRight() == null) { return 1; - }return contarHojas(n.getLeft())+ contarHojas(n.getRight()); + } + return contarHojas(n.getLeft()) + contarHojas(n.getRight()); } - - public boolean add(E element){ - if(element==null) + + public boolean add(final E element) { + if (element == null) return false; - - this.root = add(element,root); + + this.root = add(element, root); return true; } - - private Nodo add(E element, Nodo n){ - if(n == null){ + + private Nodo add(final E element, Nodo n) { + if (n == null) { n = new Nodo<>(element); - }else if(f.compare(element, n.getData()) > 0){ - n.setRight(add(element,n.getRight())); - }else if(f.compare(element, n.getData()) < 0){ - n.setLeft(add(element,n.getLeft())); + } else if (f.compare(element, n.getData()) > 0) { + n.setRight(add(element, n.getRight())); + } else if (f.compare(element, n.getData()) < 0) { + n.setLeft(add(element, n.getLeft())); } return n; } - - public boolean Insert(E element){ - if(element==null) + + public boolean insert(final E element) { + if (element == null) return false; - this.root = Insert(element,root); + this.root = insert(element, root); return true; } - - private Nodo Insert(E element, Nodo n){ - if(n == null){ - n = new Nodo<>(element); + + private Nodo insert(final E element, Nodo n) { + if (n == null) { + n = new Nodo<>(element); n.setFe(0); - }else if(f.compare(element, n.getData())>=0){ - n.setRight(Insert(element,n.getRight())); + } else if (f.compare(element, n.getData()) >= 0) { + n.setRight(insert(element, n.getRight())); n.setFe(this.calcularCarga(n)); - if(this.calcularCarga(n) >= 2 && this.calcularCarga(n.getRight()) == -1){ + if (this.calcularCarga(n) >= 2 && this.calcularCarga(n.getRight()) == -1) { n = this.rotacionDobleDerecha(n); n.setFe(this.calcularCarga(n)); - }else if(this.calcularCarga(n) >= 1 && this.calcularCarga(n.getRight())==2){ + } else if (this.calcularCarga(n) >= 1 && this.calcularCarga(n.getRight()) == 2) { n.setRight(this.rotacionSimpleIzquierda(n.getRight())); n.getRight().setFe(this.calcularCarga(n.getRight())); - }else if(this.calcularCarga(n) >= 2){ + } else if (this.calcularCarga(n) >= 2) { n = this.rotacionSimpleIzquierda(n); n.setFe(this.calcularCarga(n)); } - }else if(f.compare(element, n.getData())<0){ - n.setLeft(Insert(element,n.getLeft())); + } else if (f.compare(element, n.getData()) < 0) { + n.setLeft(insert(element, n.getLeft())); n.setFe(this.calcularCarga(n)); - if(calcularCarga(n) <= -2&& this.calcularCarga(n.getLeft())== 1){ + if (calcularCarga(n) <= -2 && this.calcularCarga(n.getLeft()) == 1) { n = this.rotacionDobleIzquierda(n); n.setFe(this.calcularCarga(n)); - }else if(this.calcularCarga(n) == -1 && this.calcularCarga(n.getLeft())== -2){ + } else if (this.calcularCarga(n) == -1 && this.calcularCarga(n.getLeft()) == -2) { n.setLeft(this.rotacionSimpleDerecha(n.getLeft())); n.getLeft().setFe(this.calcularCarga(n.getLeft())); - }else if(this.calcularCarga(n) == -2){ + } else if (this.calcularCarga(n) == -2) { n = this.rotacionSimpleDerecha(n); n.setFe(this.calcularCarga(n)); } } return n; } - - - public boolean esDegenerado(){ + + public boolean esDegenerado() { return esDegenerado(root); } - private boolean esDegenerado(Nodo p) { - if(p == null){ + + private boolean esDegenerado(final Nodo p) { + if (p == null) { return true; - } - else if(p.getLeft()!=null && p.getRight()!=null){ + } else if (p.getLeft() != null && p.getRight() != null) { return false; } - return esDegenerado(p.getLeft())&& esDegenerado(p.getRight()); + return esDegenerado(p.getLeft()) && esDegenerado(p.getRight()); } - + /** - * Calcula el Factor de Equilibrio: FE - * mide la carga del nodo. Puede ser 0, 1, 2, -1, -2 + * Calcula el Factor de Equilibrio: FE mide la carga del nodo. Puede ser 0, 1, + * 2, -1, -2 + * * @return int */ - public int calcularCarga(){ + public int calcularCarga() { return calcularCarga(root); - } - private int calcularCarga(Nodo n){ - if(n == null) + } + + private int calcularCarga(final Nodo n) { + if (n == null) return -1; - int Carga = height(n.getRight()) - height(n.getLeft()); + final int Carga = height(n.getRight()) - height(n.getLeft()); return Carga; } - - private Nodo searchNodo(E data){ - return searchNodo(data, root); - } - private Nodo searchNodo(E data, Nodo raiz){ - - if(raiz == null) - return raiz; - else if(raiz.getData().equals(data)) - return raiz; - else{ - Nodo l = searchNodo(data, raiz.getLeft()); - return (l != null) ? l: searchNodo(data, raiz.getRight()); - } - } - - /** - * Obtiene el nodo padre del nodo pasado por parametro. - * @param nodo - * @param raiz - * @return Nodo - */ - private Nodo BuscarPadre(Nodo nodo, Nodo raiz){ - Nodo nodoPapa = raiz; - if(nodo == null || nodoPapa == null || nodoPapa.getData() == nodo.getData()) - return nodo; - else if(nodoPapa.getRight() != null && nodoPapa.getLeft() != null){ - if(nodoPapa.getRight().getData() == nodo.getData() || nodoPapa.getLeft().getData() == nodo.getData()) - return nodoPapa; - else{ - Nodo p = BuscarPadre(nodo, nodoPapa.getRight()); - return (p != null) ? p: BuscarPadre(nodo, nodoPapa.getLeft()); - } - } - else if(nodoPapa.getRight() == null && nodoPapa.getLeft() != null){ - if(nodoPapa.getLeft().getData() == nodo.getData()) - return nodoPapa; - return BuscarPadre(nodo, nodoPapa.getLeft()); - }else if(nodoPapa.getRight() != null && nodoPapa.getLeft() == null){ - if(nodoPapa.getRight().getData() == nodo.getData()) - return nodoPapa; - return BuscarPadre(nodo, nodoPapa.getRight()); - } - return null; - } - + /** - * Realiza la operacion de rotacion simple derecha en el subarbol . - * Se ingresa el nodo que tiene carga 2 + * Realiza la operacion de rotacion simple derecha en el subarbol . Se ingresa + * el nodo que tiene carga 2 + * * @param nodo raiz del subarbol a rotar. * @return Nodo que pasa a ser la raiz del subarbol estructurado. */ - public Nodo rotacionSimpleIzquierda(Nodo nodo){ - if(nodo == null) + public Nodo rotacionSimpleIzquierda(final Nodo nodo) { + if (nodo == null) return null; Nodo nodoTemp; - - Nodo nodoPapa = nodo.getRight(); + + final Nodo nodoPapa = nodo.getRight(); nodo.setRight(null); - if(nodoPapa.getLeft() != null){ - nodoTemp = nodoPapa.getLeft(); - nodoPapa.setLeft(null); - nodo.setRight(nodoTemp); + if (nodoPapa.getLeft() != null) { + nodoTemp = nodoPapa.getLeft(); + nodoPapa.setLeft(null); + nodo.setRight(nodoTemp); } nodoPapa.setLeft(nodo); nodoPapa.getRight().setFe(this.calcularCarga(nodoPapa.getRight())); nodoPapa.getLeft().setFe(this.calcularCarga(nodoPapa.getLeft())); return nodoPapa; } - + /** - * Realiza la operacion de rotacion simple izquierda en el subarbol - * que tiene como raiz el nodo pasado por parametro. - * @param nodo raiz del subarbol a rotar. - * - * @return nodo nodo que pasa a ser la raiz del subarbol estructurado. - */ - public Nodo rotacionSimpleDerecha(Nodo nodo){ - if(nodo == null) + * Realiza la operacion de rotacion simple izquierda en el subarbol que tiene + * como raiz el nodo pasado por parametro. + * + * @param nodo raiz del subarbol a rotar. + * + * @return nodo nodo que pasa a ser la raiz del subarbol estructurado. + */ + public Nodo rotacionSimpleDerecha(final Nodo nodo) { + if (nodo == null) return null; Nodo nodoTemp; - - Nodo nodoPapa = nodo.getLeft(); + + final Nodo nodoPapa = nodo.getLeft(); nodo.setLeft(null); - if(nodoPapa.getRight() != null){ - nodoTemp = nodoPapa.getRight(); - nodoPapa.setRight(null); - nodo.setLeft(nodoTemp); + if (nodoPapa.getRight() != null) { + nodoTemp = nodoPapa.getRight(); + nodoPapa.setRight(null); + nodo.setLeft(nodoTemp); } - nodoPapa.setRight(nodo); + nodoPapa.setRight(nodo); nodoPapa.getRight().setFe(this.calcularCarga(nodoPapa.getRight())); nodoPapa.getLeft().setFe(this.calcularCarga(nodoPapa.getLeft())); return nodoPapa; } - - public Nodo rotacionDobleIzquierda(Nodo nodo){ - if(nodo == null) + + public Nodo rotacionDobleIzquierda(final Nodo nodo) { + if (nodo == null) return null; Nodo nodoTemp; - - Nodo nodoPapa = nodo.getLeft().getRight(); + + final Nodo nodoPapa = nodo.getLeft().getRight(); nodoTemp = nodo.getLeft(); nodo.setLeft(null); nodoTemp.setRight(null); nodoPapa.setLeft(nodoTemp); - nodoPapa.setRight(nodo); - - return nodoPapa; + nodoPapa.setRight(nodo); + + return nodoPapa; } - - public Nodo rotacionDobleDerecha(Nodo nodo){ - if(nodo == null) + + public Nodo rotacionDobleDerecha(final Nodo nodo) { + if (nodo == null) return null; Nodo nodoTemp; - - Nodo nodoPapa = nodo.getRight().getLeft(); + + final Nodo nodoPapa = nodo.getRight().getLeft(); nodoTemp = nodo.getRight(); nodo.setRight(null); nodoTemp.setLeft(null); nodoPapa.setRight(nodoTemp); - nodoPapa.setLeft(nodo); - return nodoPapa; + nodoPapa.setLeft(nodo); + return nodoPapa; } - - public E max(){ + + public E max() { return max(root); } - private E max(Nodo n){ - if(n==null)return null; - else if(n.getRight()==null){ + + private E max(final Nodo n) { + if (n == null) + return null; + else if (n.getRight() == null) { return n.getData(); - }else + } else return max(n.getRight()); } - - public E min(){ + + public E min() { return min(root); } - private E min(Nodo n){ - if(n==null)return null; - else if(n.getLeft()==null){ + + private E min(final Nodo n) { + if (n == null) + return null; + else if (n.getLeft() == null) { return n.getData(); - }else + } else return min(n.getLeft()); } - - public boolean contains(E element){ - if(element==null|| isEmpty()) return false; - return contains(element,root); - + + public boolean contains(final E element) { + if (element == null || isEmpty()) + return false; + return contains(element, root); + } - - private boolean contains(E element, Nodo n){ - if(n==null) return false; - else if(f.compare(element,n.getData()) == 0) + + private boolean contains(final E element, final Nodo n) { + if (n == null) + return false; + else if (f.compare(element, n.getData()) == 0) return true; - else if(f.compare(element, n.getData())>0){ - contains(element,n.getRight()); - }else if(f.compare(element, n.getData())<0){ - contains(element,n.getLeft()); - }return true; - } - - public void posOrde(){ + else if (f.compare(element, n.getData()) > 0) { + contains(element, n.getRight()); + } else if (f.compare(element, n.getData()) < 0) { + contains(element, n.getLeft()); + } + return true; + } + + public void posOrde() { posOrden(root); } - private void posOrden(Nodo n){ - if(n!=null){ + + private void posOrden(final Nodo n) { + if (n != null) { posOrden(n.getLeft()); posOrden(n.getRight()); System.out.println(n.getData()); } } - - public void preOrden(){ + + public void preOrden() { preOrden(root); } - private void preOrden(Nodo n){ - if(n!=null){ + + private void preOrden(final Nodo n) { + if (n != null) { System.out.println(n.getData()); preOrden(n.getLeft()); - preOrden(n.getRight()); + preOrden(n.getRight()); } } - - public void enOrden(){ + + public void enOrden() { enOrden(root); } - private void enOrden(Nodo n){ - if(n!=null){ + + private void enOrden(final Nodo n) { + if (n != null) { enOrden(n.getLeft()); - System.out.println(n.getData()); - enOrden(n.getRight()); + System.out.println(n.getData()); + enOrden(n.getRight()); } } - - public int nivel(E element){ - if (element==null|| isEmpty()|| this.contains(element)) return -1; + + public int nivel(final E element) { + if (element == null || isEmpty() || this.contains(element)) + return -1; return nivel(element, root); } - - private int nivel(E element, Nodo n){ - int num=height()-1; - if(n==null) return -1; - else if(f.compare(element,n.getData()) == 0){ + + private int nivel(final E element, final Nodo n) { + final int num = height() - 1; + if (n == null) + return -1; + else if (f.compare(element, n.getData()) == 0) { return num; - }else if(f.compare(element, n.getData())>0){ - return nivel(element,n.getRight())-1; - }else if(f.compare(element, n.getData())<0){ - return nivel(element,n.getLeft())-1; - }return -1; + } else if (f.compare(element, n.getData()) > 0) { + return nivel(element, n.getRight()) - 1; + } else if (f.compare(element, n.getData()) < 0) { + return nivel(element, n.getLeft()) - 1; + } + return -1; } - + @Override - public boolean equals(Object obj) { - if (this == null || obj == null) + public boolean equals(final Object obj) { + if (this == null || obj == null) return false; - else if (!(this instanceof AVL) || !(obj instanceof AVL)){ + else if (!(this instanceof AVL) || !(obj instanceof AVL)) { return false; } @SuppressWarnings("unchecked") final AVL other = (AVL) obj; - return equals(this.root,other.root); + return equals(this.root, other.root); } - private boolean equals(Nodo n1, Nodo n2){ - if(n1 == null && n2 == null) + + private boolean equals(final Nodo n1, final Nodo n2) { + if (n1 == null && n2 == null) return true; - else if((n1 == null && n2 != null) || (n1 != null && n2 == null)) + else if ((n1 == null && n2 != null) || (n1 != null && n2 == null)) return false; - else if(!n1.getData().equals(n2.getData())) { + else if (!n1.getData().equals(n2.getData())) { return false; } return equals(n1.getLeft(), n2.getLeft()) && equals(n1.getRight(), n2.getRight()); - } + } @Override public int hashCode() { - return super.hashCode(); //To change body of generated methods, choose Tools | Templates. - } - public Pane mostrarArbol(){ - Pane vbArbol = new Pane(); - Pane lineas = new Pane(); - - mostrarArbol(vbArbol,root,0); - for(int i = 0;i n, int nivel){ + + private void mostrarArbol(final Pane vb, final Nodo n, final int nivel) { HBox hb; - if(idexOutOfBoundsException(vb,nivel)){ + if (idexOutOfBoundsException(vb, nivel)) { hb = new HBox(); - hb.setTranslateY(70*nivel); + hb.setTranslateY(70 * nivel); vb.getChildren().add(hb); - - }else hb = (HBox)vb.getChildren().get(nivel); - Circle cir = new Circle(20); + + } else + hb = (HBox) vb.getChildren().get(nivel); + final Circle cir = new Circle(20); cir.setFill(Color.CHOCOLATE); - StackPane st = new StackPane(); + final StackPane st = new StackPane(); st.getChildren().add(cir); hb.getChildren().add(st); - if(n!=null){ - Label lbl = new Label(n.getData().toString()); + if (n != null) { + final Label lbl = new Label(n.getData().toString()); lbl.setTextFill(Color.WHITE); st.getChildren().add(lbl); - mostrarArbol(vb,n.getLeft(),nivel+1); - mostrarArbol(vb,n.getRight(),nivel+1); - }else{ - + mostrarArbol(vb, n.getLeft(), nivel + 1); + mostrarArbol(vb, n.getRight(), nivel + 1); + } else { + cir.setOpacity(0); - if(nivel borrar=null,mirar=null,cambiar=null, nPadre = null; - Nodo raizTmp = this.getRoot(); - E c_aux; - boolean salir = false; - int altDer = 0; - int altIzq = 0; - int a = 0; - - if(this.isEmpty()){ - return false; - } - - - //el nodo a borrar es la raiz? - if(this.compararDato((E)o, raizTmp.getData())==0){ - salir = true; - borrar = raizTmp; - } - - //si no es la raiz, lo buscamos - while(!salir && (raizTmp.getRight()!=null || raizTmp.getLeft()!=null)){ - - if(this.compararDato((E)o, raizTmp.getData())>0){ - if(raizTmp.getRight()!=null){ - raizTmp = raizTmp.getRight(); - }else{ - return false; - } - }else if(this.compararDato((E)o, raizTmp.getData())<0){ - - if(raizTmp.getLeft()!=null){ - raizTmp = raizTmp.getLeft(); - }else{ - return false; - } - } - - if(this.compararDato((E)o, raizTmp.getData())==0){ - salir = true; - borrar = raizTmp; - } - } - - - //existe el nodo a borrar? - if(salir){ - mirar = borrar; - - //Hoja - if(borrar.getLeft()==null && borrar.getRight()==null){ - mirar= padre(borrar); - nPadre = padre(borrar); - - //es un arbol raiz con solo un nodo raiz? - if(this.size()==1){ - this.root = null; - } - - if(nPadre.getLeft()!=null && compararDato(nPadre.getLeft().getData(), borrar.getData())==0){ - nPadre.setLeft(null); - }else if(nPadre.getRight()!=null && compararDato(nPadre.getRight().getData(), borrar.getData())==0){ - nPadre.setRight(null); - } - - borrar.setData(null); - } - - - else if(borrar.getAltura()<=2){ - - if(borrar.getLeft()!=null){ - borrar.setData(borrar.getLeft().getData()); - borrar.setLeft(null); - } - - else if(borrar.getRight()!=null){ - borrar.setData(borrar.getRight().getData()); - borrar.setRight(null); - } - } - - //Nodo no hoja - else{ - - //mayor de la izquierda - if(borrar.getLeft()!=null){ - cambiar = borrar.getLeft(); - - while(cambiar.getRight()!=null){ - cambiar = cambiar.getRight(); - } - } - - //menor de la derecha - else if(borrar.getRight()!=null){ - //cambiar = cambiar.getRight();//cambio - cambiar = borrar.getRight(); - while(cambiar.getLeft()!=null){ - cambiar = cambiar.getLeft(); - } - } - - c_aux = cambiar.getData(); - Nodo papa = padre(cambiar); - - - if(cambiar.getLeft()!=null || cambiar.getRight()!=null){ - if(cambiar.getLeft()!=null){ - cambiar.setData(cambiar.getLeft().getData()); - cambiar.setLeft(null); - }else if(cambiar.getRight()!=null){ - cambiar.setData(cambiar.getRight().getData()); - cambiar.setRight(null); - } - } - - else{ - if(papa.getLeft()!=null && compararDato(papa.getLeft().getData(), cambiar.getData())==0){ - papa.setLeft(null); - }else{ - papa.setRight(null); - } - cambiar.setData(borrar.getData()); - borrar.setData(c_aux); - } - } - - while(equilibrado(this.getRoot())<0){ - if(mirar.getRight()==null){ - altDer = 0; - }else{ - altDer = mirar.getRight().getAltura(); - } - - if(mirar.getLeft()==null){ - altIzq = 0; - }else{ - altIzq = mirar.getLeft().getAltura(); - } - - Nodo cambiar2 = estructurar(mirar, altIzq, altDer); - Nodo superior = padre(mirar); - - - if(compararDato(superior.getData(), mirar.getData())!=0){ - if(superior.getLeft()!=null && compararDato(superior.getLeft().getData(), mirar.getData())==0){ - superior.setLeft(cambiar2); - } - else if(superior.getRight()!=null && compararDato(superior.getRight().getData(), mirar.getData())==0){ - superior.setRight(cambiar2); - } - }else{ - this.root = cambiar2; - } - mirar = padre(mirar); - } - return true; - } - return false; - } - private int compararDato(E t1, E t2){ - if(this.f==null){ - return ((Comparable)t1).compareTo(t2); - }else{ - return this.f.compare(t1,t2); - } - } - public Nodo padre(Nodo nodo){ - Nodo raizTmp = this.getRoot(); - Stack > pila = new Stack >(); - pila.push(raizTmp); - while(raizTmp.getRight()!=null || raizTmp.getLeft()!=null){ - if(this.compararDato(nodo.getData(), raizTmp.getData())>0){ - if(raizTmp.getRight()!=null){ - raizTmp = raizTmp.getRight(); - } - } - else if(this.compararDato(nodo.getData(), raizTmp.getData())<0){ - if(raizTmp.getLeft()!=null){ - raizTmp = raizTmp.getLeft(); + + /** Metodos para mostrar el arbol ***/ + + // EX remove + public boolean delete(final Object o) throws ClassCastException, NullPointerException { + Nodo borrar = null, mirar = null, cambiar = null, nPadre = null; + Nodo raizTmp = this.getRoot(); + E c_aux; + boolean salir = false; + int altDer = 0; + int altIzq = 0; + + if (this.isEmpty()) { + return false; + } + + // el nodo a borrar es la raiz? + @SuppressWarnings("unchecked") + final E a = (E) o; + if (this.compararDato(a, raizTmp.getData()) == 0) { + salir = true; + borrar = raizTmp; + } + + // si no es la raiz, lo buscamos + while (!salir && (raizTmp.getRight() != null || raizTmp.getLeft() != null)) { + + if (this.compararDato(a, raizTmp.getData()) > 0) { + if (raizTmp.getRight() != null) { + raizTmp = raizTmp.getRight(); + } else { + return false; } - - } - if(this.compararDato(nodo.getData(), raizTmp.getData())==0){ - return pila.pop(); - } - - pila.push(raizTmp); - } - return pila.pop(); - } - public int size(){ - return this.preOrden1().size(); - } - private List preOrden1(){ - List lista = new ArrayList(); - Nodo nodo = this.getRoot(); - Stack> pila = new Stack>(); - - while((nodo!=null && nodo.getData()!=null) || !pila.empty()){ - if(nodo!=null){ - lista.add(nodo.getData()); - pila.push(nodo); - nodo = nodo.getLeft(); - }else{ - nodo = pila.pop(); - nodo = nodo.getRight(); - } - } - - return lista; - } - public int equilibrado(Nodo n){ - int hIzq = 0; - int hDer = 0; - - if(n==null){ - return 0; - } - - hIzq = equilibrado(n.getLeft()); - - if(hIzq < 0){ - return hIzq; - } - - hDer = equilibrado(n.getRight()); - - if(hDer <0){ - return hDer; - } - - //si no es equilibrado - if(Math.abs(hIzq - hDer)>1){ - return -1; - } - - //si el trozo de arbol es AVL devolvemos la altura - return Math.max(hIzq, hDer) + 1; - } - - private Nodo estructurar(Nodo nodo, int altIzq, int altDer){ - if(extraeFactorE(nodo)==2){ - if( extraeFactorE(nodo.getRight())==1 || extraeFactorE(nodo.getRight()) == 0){ - //nodo = rotacionSimpleIzquierda1(nodo); - nodo=rotacionSimpleIzquierda(nodo); - } - - else if(extraeFactorE(nodo.getRight())==-1){ - //nodo = rotacionCompuestaDerecha(nodo); - nodo=rotacionDobleDerecha(nodo); - } - } - else if(extraeFactorE(nodo)==-2){ - if(extraeFactorE(nodo.getLeft())==-1 || extraeFactorE(nodo.getRight())==0){ - //nodo = rotacionSimpleDerecha1(nodo); - nodo=rotacionSimpleDerecha(nodo); - } - - else if(extraeFactorE(nodo.getLeft())==1){ - //nodo = rotacionCompuestaIzquierda(nodo); - nodo=rotacionDobleIzquierda(nodo); - } - } - - return nodo; - } - /*public Nodo rotacionCompuestaIzquierda(Nodo nodo){ - Nodo nodoTmp = nodo; //57 - - nodoTmp = rotacionSimpleIzquierda1(nodoTmp.getLeft()); //param 42 | sale: 54 - - nodo.setLeft(nodoTmp); //param 54 - - nodoTmp = rotacionSimpleDerecha1(nodo); //param 54 | sale: 54 - - return nodoTmp; - } - - - public Nodo rotacionCompuestaDerecha(Nodo nodo){ - Nodo nodoTmp = nodo; - - nodoTmp = rotacionSimpleDerecha1(nodoTmp.getRight()); - - nodo.setRight(nodoTmp); - - nodoTmp= rotacionSimpleIzquierda1(nodo); - - return nodoTmp; - } - public Nodo rotacionSimpleIzquierda1(Nodo nodo){ - Nodo nodoTmp = nodo; - - nodo = nodoTmp.getRight(); //clone?? - nodoTmp.setRight(nodo.getLeft()); - - nodo.setLeft(nodoTmp); - - return nodo; - } - - - public Nodo rotacionSimpleDerecha1(Nodo nodo){ - Nodo nodoTmp = nodo; - nodo = nodoTmp.getLeft(); - - nodoTmp.setLeft(nodo.getRight()); - nodo.setRight(nodoTmp); - - return nodo; - } - */ - public int extraeFactorE(Nodo nodo){ - if(nodo!=null){ - return nodo.getFactorE(); - }else{ - return 0; - } + } else if (this.compararDato(a, raizTmp.getData()) < 0) { + + if (raizTmp.getLeft() != null) { + raizTmp = raizTmp.getLeft(); + } else { + return false; + } + } + + if (this.compararDato(a, raizTmp.getData()) == 0) { + salir = true; + borrar = raizTmp; + } + } + + // existe el nodo a borrar? + if (salir) { + mirar = borrar; + // Hoja + if (borrar.getLeft() == null && borrar.getRight() == null) { + mirar = padre(borrar); + nPadre = padre(borrar); + + // es un arbol raiz con solo un nodo raiz? + if (this.size() == 1) { + this.root = null; + } + + if (nPadre.getLeft() != null && compararDato(nPadre.getLeft().getData(), borrar.getData()) == 0) { + nPadre.setLeft(null); + } else if (nPadre.getRight() != null + && compararDato(nPadre.getRight().getData(), borrar.getData()) == 0) { + nPadre.setRight(null); + } + + borrar.setData(null); + } + + else if (borrar.getAltura() <= 2) { + + if (borrar.getLeft() != null) { + borrar.setData(borrar.getLeft().getData()); + borrar.setLeft(null); + } + + else if (borrar.getRight() != null) { + borrar.setData(borrar.getRight().getData()); + borrar.setRight(null); + } + } + + // Nodo no hoja + else { + + // mayor de la izquierda + if (borrar.getLeft() != null) { + cambiar = borrar.getLeft(); + + while (cambiar.getRight() != null) { + cambiar = cambiar.getRight(); + } + } + + // menor de la derecha + else if (borrar.getRight() != null) { + // cambiar = cambiar.getRight();//cambio + cambiar = borrar.getRight(); + while (cambiar.getLeft() != null) { + cambiar = cambiar.getLeft(); + } + } + + c_aux = cambiar.getData(); + final Nodo papa = padre(cambiar); + + if (cambiar.getLeft() != null || cambiar.getRight() != null) { + if (cambiar.getLeft() != null) { + cambiar.setData(cambiar.getLeft().getData()); + cambiar.setLeft(null); + } else if (cambiar.getRight() != null) { + cambiar.setData(cambiar.getRight().getData()); + cambiar.setRight(null); + } + } + + else { + if (papa.getLeft() != null && compararDato(papa.getLeft().getData(), cambiar.getData()) == 0) { + papa.setLeft(null); + } else { + papa.setRight(null); + } + cambiar.setData(borrar.getData()); + borrar.setData(c_aux); + } + } + + while (equilibrado(this.getRoot()) < 0) { + if (mirar.getRight() == null) { + altDer = 0; + } else { + altDer = mirar.getRight().getAltura(); + } + + if (mirar.getLeft() == null) { + altIzq = 0; + } else { + altIzq = mirar.getLeft().getAltura(); + } + + final Nodo cambiar2 = estructurar(mirar, altIzq, altDer); + final Nodo superior = padre(mirar); + + if (compararDato(superior.getData(), mirar.getData()) != 0) { + if (superior.getLeft() != null + && compararDato(superior.getLeft().getData(), mirar.getData()) == 0) { + superior.setLeft(cambiar2); + } else if (superior.getRight() != null + && compararDato(superior.getRight().getData(), mirar.getData()) == 0) { + superior.setRight(cambiar2); + } + } else { + this.root = cambiar2; + } + mirar = padre(mirar); + } + return true; + } + return false; + } + + private int compararDato(final E t1, final E t2) { + if (this.f == null) { + @SuppressWarnings("unchecked") + final Comparable tt1 = (Comparable) t1; + return tt1.compareTo(t2); + } else { + return this.f.compare(t1, t2); + } + } + + public Nodo padre(final Nodo nodo) { + Nodo raizTmp = this.getRoot(); + final Stack> pila = new Stack>(); + pila.push(raizTmp); + while (raizTmp.getRight() != null || raizTmp.getLeft() != null) { + if (this.compararDato(nodo.getData(), raizTmp.getData()) > 0) { + if (raizTmp.getRight() != null) { + raizTmp = raizTmp.getRight(); + } + } else if (this.compararDato(nodo.getData(), raizTmp.getData()) < 0) { + if (raizTmp.getLeft() != null) { + raizTmp = raizTmp.getLeft(); + } + + } + if (this.compararDato(nodo.getData(), raizTmp.getData()) == 0) { + return pila.pop(); + } + + pila.push(raizTmp); + } + return pila.pop(); + } + + public int size() { + return this.preOrden1().size(); + } + + private List preOrden1() { + final List lista = new ArrayList(); + Nodo nodo = this.getRoot(); + final Stack> pila = new Stack>(); + + while ((nodo != null && nodo.getData() != null) || !pila.empty()) { + if (nodo != null) { + lista.add(nodo.getData()); + pila.push(nodo); + nodo = nodo.getLeft(); + } else { + nodo = pila.pop(); + nodo = nodo.getRight(); + } + } + + return lista; + } + + public int equilibrado(final Nodo n) { + int hIzq = 0; + int hDer = 0; + + if (n == null) { + return 0; + } + + hIzq = equilibrado(n.getLeft()); + + if (hIzq < 0) { + return hIzq; + } + + hDer = equilibrado(n.getRight()); + + if (hDer < 0) { + return hDer; + } + + // si no es equilibrado + if (Math.abs(hIzq - hDer) > 1) { + return -1; + } + + // si el trozo de arbol es AVL devolvemos la altura + return Math.max(hIzq, hDer) + 1; + } + + private Nodo estructurar(Nodo nodo, final int altIzq, final int altDer) { + if (extraeFactorE(nodo) == 2) { + if (extraeFactorE(nodo.getRight()) == 1 || extraeFactorE(nodo.getRight()) == 0) { + // nodo = rotacionSimpleIzquierda1(nodo); + nodo = rotacionSimpleIzquierda(nodo); + } + + else if (extraeFactorE(nodo.getRight()) == -1) { + // nodo = rotacionCompuestaDerecha(nodo); + nodo = rotacionDobleDerecha(nodo); + } + } else if (extraeFactorE(nodo) == -2) { + if (extraeFactorE(nodo.getLeft()) == -1 || extraeFactorE(nodo.getRight()) == 0) { + // nodo = rotacionSimpleDerecha1(nodo); + nodo = rotacionSimpleDerecha(nodo); + } + + else if (extraeFactorE(nodo.getLeft()) == 1) { + // nodo = rotacionCompuestaIzquierda(nodo); + nodo = rotacionDobleIzquierda(nodo); + } + } + + return nodo; + } + + /* + * public Nodo rotacionCompuestaIzquierda(Nodo nodo){ Nodo nodoTmp = + * nodo; //57 + * + * nodoTmp = rotacionSimpleIzquierda1(nodoTmp.getLeft()); //param 42 | sale: 54 + * + * nodo.setLeft(nodoTmp); //param 54 + * + * nodoTmp = rotacionSimpleDerecha1(nodo); //param 54 | sale: 54 + * + * return nodoTmp; } + * + * + * public Nodo rotacionCompuestaDerecha(Nodo nodo){ Nodo nodoTmp = + * nodo; + * + * nodoTmp = rotacionSimpleDerecha1(nodoTmp.getRight()); + * + * nodo.setRight(nodoTmp); + * + * nodoTmp= rotacionSimpleIzquierda1(nodo); + * + * return nodoTmp; } public Nodo rotacionSimpleIzquierda1(Nodo nodo){ + * Nodo nodoTmp = nodo; + * + * nodo = nodoTmp.getRight(); //clone?? nodoTmp.setRight(nodo.getLeft()); + * + * nodo.setLeft(nodoTmp); + * + * return nodo; } + * + * + * public Nodo rotacionSimpleDerecha1(Nodo nodo){ Nodo nodoTmp = nodo; + * nodo = nodoTmp.getLeft(); + * + * nodoTmp.setLeft(nodo.getRight()); nodo.setRight(nodoTmp); + * + * return nodo; } + */ + public int extraeFactorE(final Nodo nodo) { + if (nodo != null) { + return nodo.getFactorE(); + } else { + return 0; + } } } diff --git a/src/tda/Nodo.java b/src/tda/Nodo.java index 052521c..4ff7076 100644 --- a/src/tda/Nodo.java +++ b/src/tda/Nodo.java @@ -21,7 +21,7 @@ public class Nodo { public Nodo(E data) { this.data = data; - left=right=null; + left = right = null; } public int getFe() { @@ -55,38 +55,39 @@ public Nodo getRight() { public void setRight(Nodo right) { this.right = right; } - public int getAltura(){ - int hIzq = 0; - int hDer = 0; - - if(this.getData()==null){ - return 0; - } - - - if(this.getLeft()!=null){ - hIzq = this.getLeft().getAltura(); - }else{ - hIzq = 0; - } - - if(this.getRight()!=null){ - hDer = this.getRight().getAltura(); - }else{ - hDer = 0; - } - return Math.max(hIzq, hDer) + 1; - } - public int getFactorE(){ - int altDer = 0; - int altIzq = 0; - if(this.getRight()!=null){ - altDer = this.getRight().getAltura(); - } - if(this.getLeft()!=null){ - altIzq = this.getLeft().getAltura(); - } - return (altDer - altIzq); + + public int getAltura() { + int hIzq = 0; + int hDer = 0; + + if (this.getData() == null) { + return 0; + } + + if (this.getLeft() != null) { + hIzq = this.getLeft().getAltura(); + } else { + hIzq = 0; + } + + if (this.getRight() != null) { + hDer = this.getRight().getAltura(); + } else { + hDer = 0; + } + return Math.max(hIzq, hDer) + 1; } - + + public int getFactorE() { + int altDer = 0; + int altIzq = 0; + if (this.getRight() != null) { + altDer = this.getRight().getAltura(); + } + if (this.getLeft() != null) { + altIzq = this.getLeft().getAltura(); + } + return (altDer - altIzq); + } + } diff --git a/test/tda/AVLTest.java b/test/tda/AVLTest.java index 1db2449..4865d32 100644 --- a/test/tda/AVLTest.java +++ b/test/tda/AVLTest.java @@ -18,22 +18,19 @@ * @author ktiusk */ public class AVLTest { - - public AVLTest() { - } - + @BeforeClass public static void setUpClass() { } - + @AfterClass public static void tearDownClass() { } - + @Before public void setUp() { } - + @After public void tearDown() { } @@ -90,7 +87,7 @@ public void testHeight() { int expResult = 2; int result = instance.height(); assertEquals(expResult, result); - if(result != expResult) + if (result != expResult) fail("The test case is a prototype."); } @@ -106,7 +103,7 @@ public void testTotalNodos() { int expResult = 2; int result = instance.totalNodos(); assertEquals(expResult, result); - if(result != expResult) + if (result != expResult) fail("The test case is a prototype."); } @@ -122,7 +119,7 @@ public void testContarHojas() { int expResult = 1; int result = instance.contarHojas(); assertEquals(expResult, result); - if(result != expResult) + if (result != expResult) fail("The test case is a prototype."); } @@ -155,7 +152,7 @@ public void testInsert() { boolean result = instance.Insert(element); assertFalse(result); // TODO review the generated test code and remove the default call to fail. - if(result != expResult) + if (result != expResult) fail("The test case is a prototype."); } @@ -200,7 +197,7 @@ public void testCalcularCarga() { int expResult = -1; int result = instance.calcularCarga(); assertEquals(expResult, result); - if(result != expResult) + if (result != expResult) fail("The test case is a prototype."); } @@ -396,5 +393,5 @@ public void testMostrarArbol() { // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); } - + }