Doubt with C pointers

Asked

Viewed 90 times

0

Hello, I am looking for the problem hrs in this excerpt (implementation of an avl tree) but I can not find, I pass a Dictionary D to this function and its value is modified within the context, but it is not modified in the context where the function is called.

Dictionary. c

struct No * RotacionaEsquerda(struct No * Pai)
{
printf("Rotacionando %d para a esquerda\n", GetChave(Pai->I));

struct No * Filho = Pai->direita;
Pai->direita = Filho->esquerda;
Filho->esquerda = Pai;
return Filho;
}

void Balanceamento (struct Dicionario * D, struct No * Pai) {

int Fator = FatorDeBalanceamento (Pai);

if (Fator >= 2) {
// Arvore tendendo a direita
        Pai = RotacionaEsquerda(Pai);
        // Raiz é modificado neste contesto
        D->raiz;
} else {
    if (Fator <= -2) {
    //Arvore tendendo a esquerda

    }
}

Client. c

int main()
{
srand( time(NULL) );

struct Dicionario * D = CriaDicionario();
int totalNiveis = 0;    

while(1)
{
    char comando[20];
    if(scanf("%s", comando) < 1 || strcmp(comando, "SAIR") == 0)
        break;  

    if(strcmp(comando, "INSERIR") == 0)
    {
        struct Item I;
        Chave c;
        scanf("%d", &c);
        SetChave(&I, c);

        Inserir(D, I);
    }
    else if(strcmp(comando, "BUSCAR") == 0)
    {
        Chave c;
        scanf("%d", &c);

        int niveis = Buscar(D, c);
        printf("%d\n", niveis);
        totalNiveis += niveis;
    }
    else if(strcmp(comando, "REMOVER") == 0)
    {
        Chave c;
        scanf("%d", &c);

        Remover(D, c);
    }
    else if(strcmp(comando, "IMPRIMIR") == 0)
    {
        Imprime(D);
    }
}
printf("%d\n", totalNiveis);
return 0;
}

When printing the Dicinario D in the context of the Balancing function, it displays the correct output, but when trying to display in the context of the main function in Client. c it displays the old Dictionary D without the left and right (Rotate left working)

source code https://github.com/viniciusilidio/AED-II-TP-1

  • Vinicius, your code is very incomplete. Please arrange it so that it can be compiled so that we can test and give you an accurate answer.

  • Okay, I got the github link

  • Always provide the full code on the page, so future users can take advantage of your doubt.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.