update
This commit is contained in:
parent
c9106da1e6
commit
0c0928fe0d
Binary file not shown.
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue