Código I – para os itens de 51 a 63
1 public class Estrutura {
2 private class No {
3 int valor; int qtd; No filhoE, filhoD;
4 No(int valor) {this.valor = valor; qtd = 1;}
5 No insere(int valor) {
6 if (this.valor > valor) {
7 if (filhoE == null) { filhoE = new No(valor); return filhoE;
8 } else { return filhoE.insere(valor);
9 }
10 } else if (this.valor < valor) {
11 if (filhoD == null) { filhoD = new No(valor); return filhoD;
12 } else { return filhoD.insere(valor);
13 }
14 } else {
15 qtd++; return this;
16 }
17 }
18 void atravessa() {
19 if (filhoD != null) filhoD.atravessa();
20 System.out.print("("+valor+","+qtd+")");
21 if (filhoE != null) filhoE.atravessa();
22 }
23 }
24 String nome; No raiz;
25 Estrutura(String nome) {this.nome = nome;raiz = null;}
26 No insere(int valor) {
27 if (raiz == null) {raiz = new No(valor);return raiz;
28 } else return raiz.insere(valor);
29 }
30 void atravessa() {
31 if (raiz == null) return;
32 System.out.print(nome+"={");raiz.atravessa();System.out.print("}");
33 }
34 public static void main(String[] args) {
35 Estrutura e = new Estrutura(args[0]);
36 for (int i = 1; i < args.length; i++) {
37 e.insere(Integer.parseInt(args[i]));
38 }
39 e.atravessa();
40 }
41 }
O código I representa um programa Java plenamente funcional. Julgue os itens de 51 a 59, acerca das informações apresentadas no código e dos conceitos de construção de algoritmos, estrutura de dados, orientação a objetos e linguagem de programação Java.
1 public class Estrutura {
2 private class No {
3 int valor; int qtd; No filhoE, filhoD;
4 No(int valor) {this.valor = valor; qtd = 1;}
5 No insere(int valor) {
6 if (this.valor > valor) {
7 if (filhoE == null) { filhoE = new No(valor); return filhoE;
8 } else { return filhoE.insere(valor);
9 }
10 } else if (this.valor < valor) {
11 if (filhoD == null) { filhoD = new No(valor); return filhoD;
12 } else { return filhoD.insere(valor);
13 }
14 } else {
15 qtd++; return this;
16 }
17 }
18 void atravessa() {
19 if (filhoD != null) filhoD.atravessa();
20 System.out.print("("+valor+","+qtd+")");
21 if (filhoE != null) filhoE.atravessa();
22 }
23 }
24 String nome; No raiz;
25 Estrutura(String nome) {this.nome = nome;raiz = null;}
26 No insere(int valor) {
27 if (raiz == null) {raiz = new No(valor);return raiz;
28 } else return raiz.insere(valor);
29 }
30 void atravessa() {
31 if (raiz == null) return;
32 System.out.print(nome+"={");raiz.atravessa();System.out.print("}");
33 }
34 public static void main(String[] args) {
35 Estrutura e = new Estrutura(args[0]);
36 for (int i = 1; i < args.length; i++) {
37 e.insere(Integer.parseInt(args[i]));
38 }
39 e.atravessa();
40 }
41 }
O código I representa um programa Java plenamente funcional. Julgue os itens de 51 a 59, acerca das informações apresentadas no código e dos conceitos de construção de algoritmos, estrutura de dados, orientação a objetos e linguagem de programação Java.
O programa declara dois métodos mutuamente recursivos.
CertoErrado