xbubbax
28-05-2008, 13:45
Qualcuno mi dice se ci sono errori in queste funzioni "base" per gli alberi binari?
Sembrano perfette, visto che ho preso spunto dal libro, ma di da molti errori quando le uso nei programmi
#include <stdio.h>
#include <stdlib.h>
struct tree
{
int dato;
struct tree *sx, *dx;
};
typedef struct tree tree;
int Is_Empty(tree Radice)
{
if(Radice==NULL){return 1;}
return 0;
}
tree Albero_Vuoto(void)
{
return NULL;
}
int Valore_Etichetta(tree Radice)
{
if(Radice!=NULL){return Radice->dato;}
}
tree Sinistro(tree Radice)
{
if(Radice!=NULL){return Radice->sx;}
return NULL;
}
tree Destro(tree Radice)
{
if(Radice!=NULL){return Radice->dx;}
return NULL;
}
tree Costruisci_Albero(int Etichetta, tree s, tree d)
{
tree Radice;
Radice=(tree)malloc(sizeof(nodo));
Radice->dato=Etichetta;
Radice->sx=s;
Radice->dx=d;
return Radice;
}
void Inorder(tree Radice)
{
if(Radice!=NULL)
{
Inorder(Radice->sx);
printf("%d ", Valore_Etichetta(Radice));
Inorder(Radice->dx);
}
}
void Preorder(tree Radice)
{
if(Radice!=NULL)
{
printf("%d ", Valore_Etichetta(Radice));
Preorder(Radice->sx);
Preorder(Radice->dx);
}
}
void Postorder(tree Radice)
{
if(Radice!=NULL)
{
Postorder(Radice->sx);
Postorder(Radice->dx);
printf("%d ", Valore_Etichetta(Radice));
}
}
Sembrano perfette, visto che ho preso spunto dal libro, ma di da molti errori quando le uso nei programmi
#include <stdio.h>
#include <stdlib.h>
struct tree
{
int dato;
struct tree *sx, *dx;
};
typedef struct tree tree;
int Is_Empty(tree Radice)
{
if(Radice==NULL){return 1;}
return 0;
}
tree Albero_Vuoto(void)
{
return NULL;
}
int Valore_Etichetta(tree Radice)
{
if(Radice!=NULL){return Radice->dato;}
}
tree Sinistro(tree Radice)
{
if(Radice!=NULL){return Radice->sx;}
return NULL;
}
tree Destro(tree Radice)
{
if(Radice!=NULL){return Radice->dx;}
return NULL;
}
tree Costruisci_Albero(int Etichetta, tree s, tree d)
{
tree Radice;
Radice=(tree)malloc(sizeof(nodo));
Radice->dato=Etichetta;
Radice->sx=s;
Radice->dx=d;
return Radice;
}
void Inorder(tree Radice)
{
if(Radice!=NULL)
{
Inorder(Radice->sx);
printf("%d ", Valore_Etichetta(Radice));
Inorder(Radice->dx);
}
}
void Preorder(tree Radice)
{
if(Radice!=NULL)
{
printf("%d ", Valore_Etichetta(Radice));
Preorder(Radice->sx);
Preorder(Radice->dx);
}
}
void Postorder(tree Radice)
{
if(Radice!=NULL)
{
Postorder(Radice->sx);
Postorder(Radice->dx);
printf("%d ", Valore_Etichetta(Radice));
}
}