atualização
This commit is contained in:
parent
cac0d53b4e
commit
a322e474ae
|
|
@ -1,6 +1,6 @@
|
||||||
class Celula {
|
class Celula {
|
||||||
private int elemento;
|
public int elemento;
|
||||||
private Celula inf, sup, esq, dir;
|
public Celula inf, sup, esq, dir;
|
||||||
|
|
||||||
public Celula(){
|
public Celula(){
|
||||||
this(0, null, null, null, null);
|
this(0, null, null, null, null);
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,7 @@ class Matriz {
|
||||||
private int linha, coluna;
|
private int linha, coluna;
|
||||||
|
|
||||||
public Matriz (){
|
public Matriz (){
|
||||||
this.linha = this.coluna = 3;
|
Matriz(3, 3);
|
||||||
|
|
||||||
//alocar a matriz com this.linha linhas e this.coluna colunas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matriz (int linha, int coluna){
|
public Matriz (int linha, int coluna){
|
||||||
|
|
@ -15,10 +13,18 @@ class Matriz {
|
||||||
//alocar a matriz com this.linha linhas e this.coluna colunas
|
//alocar a matriz com this.linha linhas e this.coluna colunas
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Matriz soma (Matriz m) {
|
public Matriz soma (Matriz m) {
|
||||||
Matriz resp = null;
|
Matriz resp = null;
|
||||||
|
|
||||||
if(this.linha == m.linha && this.coluna == m.coluna){
|
if(this.linha == m.linha && this.coluna == m.coluna){
|
||||||
|
resp = new Matriz(this.linha, this.coluna);
|
||||||
|
for(){
|
||||||
|
for(){
|
||||||
|
//sendo c (pont em resp), a (em this) e b (em m)
|
||||||
|
c.elemento = a.elemento + b.elemento;
|
||||||
|
}
|
||||||
|
}
|
||||||
//...
|
//...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +53,6 @@ class Matriz {
|
||||||
|
|
||||||
public void mostrarDiagonalSecundaria (){
|
public void mostrarDiagonalSecundaria (){
|
||||||
if(isQuadrada() == true){
|
if(isQuadrada() == true){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -199,3 +199,58 @@ void antecessor(No** i, No** j) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metodo publico iterativo para remover elemento.
|
||||||
|
* @param x Elemento a ser removido.
|
||||||
|
*/
|
||||||
|
void removerSucessor(int x) {
|
||||||
|
removerRecSucessor(x, &raiz);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metodo privado recursivo para remover elemento.
|
||||||
|
* @param x Elemento a ser removido.
|
||||||
|
* @param i No** endereco do ponteiro No
|
||||||
|
*/
|
||||||
|
void removerRecSucessor(int x, No** i) {
|
||||||
|
if (*i == NULL) {
|
||||||
|
errx(1, "Erro ao remover!");
|
||||||
|
|
||||||
|
} else if (x < (*i)->elemento) {
|
||||||
|
removerRec(x, &((*i)->esq));
|
||||||
|
|
||||||
|
} else if (x > (*i)->elemento) {
|
||||||
|
removerRec(x, &((*i)->dir));
|
||||||
|
|
||||||
|
} else if ((*i)->dir == NULL) {
|
||||||
|
No* del = *i;
|
||||||
|
*i = (*i)->esq;
|
||||||
|
free(del);
|
||||||
|
|
||||||
|
} else if ((*i)->esq == NULL) {
|
||||||
|
No* del = *i;
|
||||||
|
*i = (*i)->dir;
|
||||||
|
free(del);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
sucessor(i, &((*i)->dir));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metodo para trocar no removido pelo sucessor.
|
||||||
|
* @param i No** endereco do ponteiro No que contem o elemento removido.
|
||||||
|
* @param j No** endereco do ponteiro No da subarvore esquerda.
|
||||||
|
*/
|
||||||
|
void sucessor(No** i, No** j) {
|
||||||
|
if ((*j)->esq != NULL) {
|
||||||
|
sucessor(i, &((*j)->esq));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
No* del = *j;
|
||||||
|
(*i)->elemento = (*j)->elemento;
|
||||||
|
(*j) = (*j)->dir;
|
||||||
|
free(del);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ void caminharPosRec(No*);
|
||||||
void inserirRec(int, No**);
|
void inserirRec(int, No**);
|
||||||
void removerRec(int, No**);
|
void removerRec(int, No**);
|
||||||
void antecessor(No**, No**);
|
void antecessor(No**, No**);
|
||||||
|
void removerRecSucessor(int, No**);
|
||||||
|
void sucessor(No**, No**);
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
bool pesquisar(int);
|
bool pesquisar(int);
|
||||||
|
|
@ -23,3 +25,4 @@ void caminharPre();
|
||||||
void caminharPos();
|
void caminharPos();
|
||||||
void inserir(int);
|
void inserir(int);
|
||||||
void remover(int);
|
void remover(int);
|
||||||
|
void removerSucessor(int);
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -46,10 +46,10 @@ int main(){
|
||||||
printf("\nVoltando com a árvore inicial");
|
printf("\nVoltando com a árvore inicial");
|
||||||
printf("\nRemover: 3");
|
printf("\nRemover: 3");
|
||||||
printf("\nCaminhar: central, pre e pos\n");
|
printf("\nCaminhar: central, pre e pos\n");
|
||||||
remover(2);
|
removerSucessor(2);
|
||||||
inserir(1);
|
inserir(1);
|
||||||
inserir(2);
|
inserir(2);
|
||||||
remover(3);
|
removerSucessor(3);
|
||||||
|
|
||||||
caminharCentral();
|
caminharCentral();
|
||||||
caminharPre();
|
caminharPre();
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,20 @@ public class Agenda {
|
||||||
private No raiz;
|
private No raiz;
|
||||||
|
|
||||||
public Agenda() {
|
public Agenda() {
|
||||||
/*raiz = new No ('M');
|
raiz = new No ('M');
|
||||||
raiz.esq = new No ('F');
|
raiz.esq = new No ('F');
|
||||||
raiz.dir = new No ('T');
|
raiz.dir = new No ('T');
|
||||||
raiz.esq.esq = new No ('C');*/
|
raiz.esq.esq = new No ('C');
|
||||||
raiz = null;
|
|
||||||
//inserir todas as 26 letras do alfabeto...
|
//inserir todas as 26 letras do alfabeto...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public boolean pesquisarNome(String nome) {
|
public boolean pesquisarNome(String nome) {
|
||||||
return pesquisarNome(raiz, nome);
|
return pesquisarNome(raiz, nome);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue