Skip to content

Commit

Permalink
Removed inused imports and fix some peek problems
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVelezLl committed May 8, 2020
1 parent 942606f commit 7810f59
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 52 deletions.
89 changes: 41 additions & 48 deletions src/Interfaz/InterfazArbol.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package Interfaz;

import java.util.ArrayList;
import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
Expand All @@ -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;

Expand All @@ -36,17 +29,17 @@ public class InterfazArbol {
private Pane root;
private AVL<Integer> 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);
Expand All @@ -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);
Expand All @@ -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;
}
}
11 changes: 7 additions & 4 deletions src/tda/AVL.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,11 @@ public boolean equals(Object obj) {
else if (!(this instanceof AVL) || !(obj instanceof AVL)){
return false;
}
@SuppressWarnings("unchecked")
final AVL<E> other = (AVL<E>) obj;
return equals(this.root,other.root);
}
private boolean equals(Nodo n1, Nodo n2){
private boolean equals(Nodo<E> n1, Nodo<E> n2){
if(n1 == null && n2 == null)
return true;
else if((n1 == null && n2 != null) || (n1 != null && n2 == null))
Expand Down Expand Up @@ -502,7 +503,7 @@ private boolean idexOutOfBoundsException(Pane vb, int n){
public boolean delete(Object o) throws ClassCastException, NullPointerException{
Nodo<E> borrar=null,mirar=null,cambiar=null, nPadre = null;
Nodo<E> raizTmp = this.getRoot();
E c_aux, d_aux;
E c_aux;
boolean salir = false;
int altDer = 0;
int altIzq = 0;
Expand All @@ -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;
Expand Down Expand Up @@ -679,7 +681,8 @@ public Nodo<E> padre(Nodo<E> 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();
Expand Down

0 comments on commit 7810f59

Please sign in to comment.