I am putting together a hospital program and the order of the patients will be by a binary tree, taking into account a degree of urgency existing in the patient struct, as I show below. My question is: Do you have any special treatment for 3 hands? Because when I run the program it seems that it is not saved in the struct tree when I try to show the tree in order it is always empty.
Patient and Tree Structures:
typedef struct Paciente{
char nome[50];
char cpf[50];
char sexo[20];
char sintomas[500];
int telefone;
int idade;
int codi;
int urg;
struct Paciente *prox;
}paciente;
typedef struct Arvore{
struct Paciente *No;
struct Arvore *Esq;
struct Arvore *Dir;
}arvore;
Add and Show tree functions:
void adicionar(arvore **Arv, paciente *pac){
arvore *temp = NULL;
if (*Arv == NULL){
temp = (arvore*)malloc(sizeof(arvore));
temp->Esq = NULL;
temp->Dir = NULL;
temp->No = pac;
*Arv = temp;
}
else {
if (pac->urg < ((*Arv)->No->urg)){
adicionar(&((*Arv)->Esq), pac);
}
else{
adicionar(&((*Arv)->Dir), pac);
}
}
}
// Em Ordem (Do menor pro maior)
void Mostrar(arvore *Arv){
if(Arv != NULL){
Mostrar(Arv->Esq);
printf("Nome: %s\nCPF: %s\nSexo: %s\nIdade: %d\nTelefone: %d\nSintomas: %s\nUrgencia: %d\nCódigo: %d\n", Arv->No->nome, Arv->No->cpf, Arv->No->sexo, Arv->No->idade, Arv->No->telefone, Arv->No->sintomas, Arv->No->urg, Arv->No->codi);
Mostrar(Arv->Dir);
}
}
In Main I create it like this:
arvore *Arv = NULL;