Skip to content

Commit 258d8ce

Browse files
committed
Refact Java code using google-java-format
1 parent 035bc0c commit 258d8ce

31 files changed

+1114
-1149
lines changed

src/java/ArvoreBinaria.java

+89-97
Original file line numberDiff line numberDiff line change
@@ -2,117 +2,109 @@
22
* Utiliza a classe No
33
*/
44

5-
65
public class ArvoreBinaria {
76

8-
9-
public static void main(String[] args) {
10-
No raiz = new No(9);
11-
12-
inserir(raiz, 3);
13-
inserir(raiz, 4);
14-
inserir(raiz, 6);
15-
inserir(raiz, 7);
16-
inserir(raiz, 8);
17-
inserir(raiz, 10);
18-
inserir(raiz, 13);
19-
inserir(raiz, 14);
20-
21-
System.out.println();
22-
23-
System.out.printf("Em ordem: ");
24-
emOrdem(raiz);
25-
System.out.println();
26-
27-
System.out.printf("Pós-fixado: ");
28-
posFixado(raiz);
29-
System.out.println();
30-
31-
System.out.printf("Pré-fixado: ");
32-
preFixado(raiz);
33-
System.out.println();
34-
35-
System.out.println("Remove Valor: "+ removeValorMinimoDaArvore(raiz));
36-
System.out.println("Altura Arvore: "+AlturaArvore(raiz));
37-
}
38-
39-
40-
public static void inserir(No node, int valor) {
41-
if (node != null) {
42-
if (valor < node.getChave()) {
43-
if (node.getEsq() != null) {
44-
inserir(node.getEsq(), valor);
45-
} else {
46-
System.out.println(" Inserindo " + valor + " a esquerda de " + node.getChave());
47-
node.setEsq(new No(valor)); ;
48-
}
49-
} else if (valor > node.getChave()) {
50-
if (node.getDir() != null) {
51-
inserir(node.getDir(), valor);
52-
} else {
53-
System.out.println(" Inserindo " + valor + " a direita de " + node.getChave());
54-
node.setDir(new No(valor));
55-
}
56-
}
7+
public static void main(String[] args) {
8+
No raiz = new No(9);
9+
10+
inserir(raiz, 3);
11+
inserir(raiz, 4);
12+
inserir(raiz, 6);
13+
inserir(raiz, 7);
14+
inserir(raiz, 8);
15+
inserir(raiz, 10);
16+
inserir(raiz, 13);
17+
inserir(raiz, 14);
18+
19+
System.out.println();
20+
21+
System.out.printf("Em ordem: ");
22+
emOrdem(raiz);
23+
System.out.println();
24+
25+
System.out.printf("Pós-fixado: ");
26+
posFixado(raiz);
27+
System.out.println();
28+
29+
System.out.printf("Pré-fixado: ");
30+
preFixado(raiz);
31+
System.out.println();
32+
33+
System.out.println("Remove Valor: " + removeValorMinimoDaArvore(raiz));
34+
System.out.println("Altura Arvore: " + AlturaArvore(raiz));
35+
}
36+
37+
public static void inserir(No node, int valor) {
38+
if (node != null) {
39+
if (valor < node.getChave()) {
40+
if (node.getEsq() != null) {
41+
inserir(node.getEsq(), valor);
42+
} else {
43+
System.out.println(" Inserindo " + valor + " a esquerda de " + node.getChave());
44+
node.setEsq(new No(valor));
45+
;
5746
}
58-
}
59-
60-
public static void preFixado(No no) {
61-
if (no != null) {
62-
System.out.print(no.getChave() + " ");
63-
preFixado(no.getEsq());
64-
preFixado(no.getDir());
47+
} else if (valor > node.getChave()) {
48+
if (node.getDir() != null) {
49+
inserir(node.getDir(), valor);
50+
} else {
51+
System.out.println(" Inserindo " + valor + " a direita de " + node.getChave());
52+
node.setDir(new No(valor));
6553
}
54+
}
6655
}
56+
}
6757

68-
public static void posFixado(No no) {
69-
if (no != null) {
70-
posFixado(no.getEsq());
71-
posFixado(no.getDir());
72-
System.out.print(no.getChave() + " ");
73-
}
58+
public static void preFixado(No no) {
59+
if (no != null) {
60+
System.out.print(no.getChave() + " ");
61+
preFixado(no.getEsq());
62+
preFixado(no.getDir());
7463
}
64+
}
7565

76-
public static void emOrdem(No no) {
77-
if (no != null) {
78-
emOrdem(no.getEsq());
79-
System.out.print(no.getChave() + " ");
80-
emOrdem(no.getDir());
81-
}
66+
public static void posFixado(No no) {
67+
if (no != null) {
68+
posFixado(no.getEsq());
69+
posFixado(no.getDir());
70+
System.out.print(no.getChave() + " ");
8271
}
72+
}
8373

84-
public static No removeValorMinimoDaArvore(No node) {
85-
if (node == null) {
86-
System.out.println(" ERROR ");
87-
} else if (node.getEsq() != null) {
88-
node.setEsq(removeValorMinimoDaArvore(node.getEsq()));
89-
return node;
90-
} else {
91-
return node.getDir();
92-
}
93-
return null;
74+
public static void emOrdem(No no) {
75+
if (no != null) {
76+
emOrdem(no.getEsq());
77+
System.out.print(no.getChave() + " ");
78+
emOrdem(no.getDir());
79+
}
80+
}
81+
82+
public static No removeValorMinimoDaArvore(No node) {
83+
if (node == null) {
84+
System.out.println(" ERROR ");
85+
} else if (node.getEsq() != null) {
86+
node.setEsq(removeValorMinimoDaArvore(node.getEsq()));
87+
return node;
88+
} else {
89+
return node.getDir();
9490
}
91+
return null;
92+
}
9593

96-
public static int AlturaArvore(No no){
94+
public static int AlturaArvore(No no) {
9795

98-
if(no == null){
99-
return -1;
100-
}
101-
else{
96+
if (no == null) {
97+
return -1;
98+
} else {
10299

103-
int esquerda = AlturaArvore(no.getEsq());
104-
int direita = AlturaArvore(no.getDir());
100+
int esquerda = AlturaArvore(no.getEsq());
101+
int direita = AlturaArvore(no.getDir());
105102

106-
if(esquerda < direita ){
107-
return direita+1;
108-
}
109-
else{
110-
return esquerda+1;
111-
}
112-
}
103+
if (esquerda < direita) {
104+
return direita + 1;
105+
} else {
106+
return esquerda + 1;
107+
}
113108
}
114-
109+
}
115110
}
116-
117-
118-

0 commit comments

Comments
 (0)