diff --git a/aula/u07 Árvores binárias/unidade07g_árvoreBinaria_Estruturas Híbridas.pdf b/aula/u07 Árvores binárias/unidade07g_árvoreBinaria_Estruturas Híbridas.pdf index 75c9c68..03a2692 100644 Binary files a/aula/u07 Árvores binárias/unidade07g_árvoreBinaria_Estruturas Híbridas.pdf and b/aula/u07 Árvores binárias/unidade07g_árvoreBinaria_Estruturas Híbridas.pdf differ diff --git a/fonte/u06 Estruturas de dados básicas flexíveis/java/matriz/Celula.java b/fonte/u06 Estruturas de dados básicas flexíveis/java/matriz/Celula.java index ab3ba18..e5723ff 100644 --- a/fonte/u06 Estruturas de dados básicas flexíveis/java/matriz/Celula.java +++ b/fonte/u06 Estruturas de dados básicas flexíveis/java/matriz/Celula.java @@ -3,7 +3,7 @@ class Celula { public Celula inf, sup, esq, dir; public Celula(){ - this(0, null, null, null, null); + this(0); } public Celula(int elemento){ diff --git a/fonte/u07 Árvores binárias/arvoreArvore/ArvoreArvore.java b/fonte/u07 Árvores binárias/arvoreArvore/ArvoreArvore.java index fc136dd..66949dc 100644 --- a/fonte/u07 Árvores binárias/arvoreArvore/ArvoreArvore.java +++ b/fonte/u07 Árvores binárias/arvoreArvore/ArvoreArvore.java @@ -17,7 +17,7 @@ public class ArvoreArvore { } public void inserir(char letra){ - //igual ao da árvore binária padrão!!! + //igualzinho (mesmo, de verdade) ao da árvore binária padrão!!! } @@ -41,7 +41,7 @@ public class ArvoreArvore { } - private No inserir(String s, No2 i) throws Exception { + private No2 inserir(String s, No2 i) throws Exception { if (i == null) { i = new No2(x); @@ -59,6 +59,29 @@ public class ArvoreArvore { } + public void mostrar(){ + mostrar(raiz); + } + + public void mostrar(No i){ + if (i != null){ + mostrar(i.esq); + //System.out.println("Letra: " + i.elemento); + mostrar(i.outra); + mostrar(i.dir); + } + } + + public void mostrar(No2 i){ + if (i != null){ + mostrar(i.esq); + System.out.println(i.elemento); + mostrar(i.dir); + } + } + + + public boolean hasStringTam10(){ return hasStringTam10(raiz); } @@ -80,6 +103,26 @@ public class ArvoreArvore { } + public boolean hasStringTam10(char c){ + return hasStringTam10(raiz, c); + } + + public boolean hasStringTam10(No i, char c){ + boolean resp; + if (i == null) { + resp = false; + + } else if (c < i.elemento) { + resp = hasStringTam10(i.esq, c); + + } else if (c > i.elemento) { + resp = hasStringTam10(i.dir, c); + + } else { + resp = hasStringTam10(i.outro); + } + return resp; + } @@ -100,14 +143,14 @@ public class ArvoreArvore { if (no == null) { resp = false; - } else if (x.charAt(0) == no.elemento) { - resp = pesquisarSegundaArvore(no.outro, x); - } else if (x.charAt(0) < no.elemento) { resp = pesquisar(no.esq, x); - } else { + } else if (x.charAt(0) > no.elemento) { resp = pesquisar(no.dir, x); + + } else { + resp = pesquisarSegundaArvore(no.outro, x); } return resp; } @@ -117,22 +160,18 @@ public class ArvoreArvore { if (no == null) { resp = false; - } else if (x.equals(no.elemento)) { - resp = true; - } else if (x.compareTo(no.elemento) < 0) { resp = pesquisarSegundaArvore(no.esq, x); - } else { + } else if (x.compareTo(no.elemento) > 0) { resp = pesquisarSegundaArvore(no.dir, x); + + } else { + resp = true; } return resp; } - private void inserir(char c){ - System.out.println(c); - //implementar - } public int contPalavra(char letra){ return contPalavra(letra, raiz); @@ -164,6 +203,21 @@ public class ArvoreArvore { } return resp; } - - } + + + + + + + + + + + + + + + + + diff --git a/fonte/u07 Árvores binárias/matrizDeLista/Celula.java b/fonte/u07 Árvores binárias/matrizDeLista/Celula.java new file mode 100644 index 0000000..866b654 --- /dev/null +++ b/fonte/u07 Árvores binárias/matrizDeLista/Celula.java @@ -0,0 +1,26 @@ +/** + * Celula (pilha, lista e fila dinamica) + * @author Max do Val Machado + * @version 2 01/2015 + */ +class Celula { + public int elemento; // Elemento inserido na celula. + public Celula prox; // Aponta a celula prox. + + + /** + * Construtor da classe. + */ + public Celula() { + this(0); + } + + /** + * Construtor da classe. + * @param elemento int inserido na celula. + */ + public Celula(int elemento) { + this.elemento = elemento; + this.prox = null; + } +} diff --git a/fonte/u07 Árvores binárias/matrizDeLista/CelulaMat.java b/fonte/u07 Árvores binárias/matrizDeLista/CelulaMat.java new file mode 100644 index 0000000..a1cf246 --- /dev/null +++ b/fonte/u07 Árvores binárias/matrizDeLista/CelulaMat.java @@ -0,0 +1,22 @@ +class CelulaMat { + public int elemento; + public CelulaMat inf, sup, esq, dir; + public Celula primeiro, ultimo; + + public CelulaMat(){ + this(0); + } + + public CelulaMat(int elemento){ + this(elemento, null, null, null, null); + } + + public CelulaMat(int elemento, CelulaMat inf, CelulaMat sup, CelulaMat esq, CelulaMat dir){ + this.elemento = elemento; + this.inf = inf; + this.sup = sup; + this.esq = esq; + this.dir = dir; + this.primeiro = this.ultimo = new Celula(); + } +} diff --git a/fonte/u07 Árvores binárias/matrizDeLista/MatrizDeLista.java b/fonte/u07 Árvores binárias/matrizDeLista/MatrizDeLista.java new file mode 100644 index 0000000..6d67a48 --- /dev/null +++ b/fonte/u07 Árvores binárias/matrizDeLista/MatrizDeLista.java @@ -0,0 +1,57 @@ +class MatrizDeLista { + private CelulaMat inicio; + private int linha, coluna; + + public MatrizDeLista(){ + this(3, 3); + } + + public MatrizDeLista(int linha, int coluna){ + this.linha = linha; + this.coluna = coluna; + + //alocar todas as celulas da matriz!!! + //igual ao construtor da matriz flexível!!! + //Lembre-se que cada lista eh criada atutomaticamente no construtor de CelulaMat(). + } + + + boolean pesquisar(int elemento){ + boolean resp = false; + + for(CelulaMat i = inicio; !resp && i != null; i = i.dir){ + for(CelulaMat j = i; !resp && j != null; j = j.inf){ + if(j.elemento == elemento){ + resp = true; + } else { + for(Celula k = j.primeiro.prox; k != null; k = k.prox){ + if(k.elemento == elemento){ + resp = true; + k = j.ultimo; + } + } + } + } + } + + return resp; + } + + boolean pesquisar(int i, int j, int elemento){ + boolean resp = false; + CelulaMat pi, pj; + + for(int ii = 0, pi = inicio; ii < i; ii++, pi = pi.dir){ + for(int jj = 0, pj = pi; jj < j; jj++, pj = pj.inf); + } + + for(Celula k = pj.primeiro.prox; k != null; k = k.prox){ + if(k.elemento == elemento){ + resp = true; + k = j.ultimo; + } + } + + } + +}