atualização
This commit is contained in:
parent
cac0d53b4e
commit
a322e474ae
|
|
@ -1,6 +1,6 @@
|
|||
class Celula {
|
||||
private int elemento;
|
||||
private Celula inf, sup, esq, dir;
|
||||
public int elemento;
|
||||
public Celula inf, sup, esq, dir;
|
||||
|
||||
public Celula(){
|
||||
this(0, null, null, null, null);
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@ class Matriz {
|
|||
private int linha, coluna;
|
||||
|
||||
public Matriz (){
|
||||
this.linha = this.coluna = 3;
|
||||
|
||||
//alocar a matriz com this.linha linhas e this.coluna colunas
|
||||
Matriz(3, 3);
|
||||
}
|
||||
|
||||
public Matriz (int linha, int coluna){
|
||||
|
|
@ -15,10 +13,18 @@ class Matriz {
|
|||
//alocar a matriz com this.linha linhas e this.coluna colunas
|
||||
}
|
||||
|
||||
|
||||
public Matriz soma (Matriz m) {
|
||||
Matriz resp = null;
|
||||
|
||||
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 (){
|
||||
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 removerRec(int, No**);
|
||||
void antecessor(No**, No**);
|
||||
void removerRecSucessor(int, No**);
|
||||
void sucessor(No**, No**);
|
||||
|
||||
void start();
|
||||
bool pesquisar(int);
|
||||
|
|
@ -23,3 +25,4 @@ void caminharPre();
|
|||
void caminharPos();
|
||||
void inserir(int);
|
||||
void remover(int);
|
||||
void removerSucessor(int);
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -46,10 +46,10 @@ int main(){
|
|||
printf("\nVoltando com a árvore inicial");
|
||||
printf("\nRemover: 3");
|
||||
printf("\nCaminhar: central, pre e pos\n");
|
||||
remover(2);
|
||||
removerSucessor(2);
|
||||
inserir(1);
|
||||
inserir(2);
|
||||
remover(3);
|
||||
removerSucessor(3);
|
||||
|
||||
caminharCentral();
|
||||
caminharPre();
|
||||
|
|
|
|||
|
|
@ -2,14 +2,20 @@ public class Agenda {
|
|||
private No raiz;
|
||||
|
||||
public Agenda() {
|
||||
/*raiz = new No ('M');
|
||||
raiz = new No ('M');
|
||||
raiz.esq = new No ('F');
|
||||
raiz.dir = new No ('T');
|
||||
raiz.esq.esq = new No ('C');*/
|
||||
raiz = null;
|
||||
raiz.esq.esq = new No ('C');
|
||||
//inserir todas as 26 letras do alfabeto...
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean pesquisarNome(String nome) {
|
||||
return pesquisarNome(raiz, nome);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue