Alguém pode me ajudar neste código em C, é uma arvore ?

6 respostas
programação
F

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct no

{

char chave[15];

struct no<em>esq;

struct no</em>dir;

struct no*pai;

};

typedef struct no No;
void inserir(No<em>x)

{

printf("%s",x->chave);

No</em>y=NULL;
while(x!=NULL)
{
    y=x;
    No*z= NULL;
    if(strcmp(x->chave,y->chave)==0)
        printf("%s",x->chave);
    if(strcmp(y->chave,z->chave)>0)
        printf("%s",y->chave);
    if(strcmp(y->chave,z->chave)<0)
        printf("%s",z->chave);
}
}

int main()

{
return 0;

}

6 Respostas

P

Qual o problema? Seria o looping infinito na função void inserir(No x) ?

F

Queria saber ser estou fazendo correto

P

Já executou o código?
Isso ira gerar um looping infinito while(x!=NULL)

F

Já executei , não gera loop infinito não , mas você manja de arvores ?

P

Ainda lembro alguma coisa do que vi na faculdade.

F

Hum tenho que fazer baseado neste pseudocodigo
TREE_INSERT( T, z )
1 y ← NULL
2 x ← raiz( T )
3 enquanto x ≠ NULL, faça:
4 y ← x
5 se chave( z ) < chave ( x ), então:
6 x ← esquerda( x )
7 senão: x ← direita ( x )
8 pai( z ) ← y
9 se y = NULL, então:
10 raiz ( T ) ← z
11 senão: se chave ( z ) < chave ( y ), então:
12 esquerda( y ) ← z
13 senão: direita( y ) ← z

Criado 18 de novembro de 2018
Ultima resposta 18 de nov. de 2018
Respostas 6
Participantes 2