////////////////////////////////////
// REALIZZAZIONE DI ALBERI BINARI //
// AUTORE: Farinelli Agnese       //
// DATA: 26 Febbraio 2009         //
////////////////////////////////////

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

typedef struct bincella * binalbero;
typedef struct bincella * nodo;
typedef int tipoelem;

struct bincella {
  tipoelem valore;
  nodo sinistro, destro, genitore;
};

// Funzione CREABINALBERO
// crea un albero binario vuoto
binalbero CREABINALBERO(){
  binalbero T = NULL;
  return T;
}
// Funzione BINALBEROVUOTO
// controlla se l'albero è vuoto. 
// Restituisce 1 se è VERO, 0 se è FALSO.
int BINALBEROVUOTO(binalbero T){
  if(T == NULL)
    return 1;
  else
    return 0;
}

// Funzione BINRADICE
// Crea un albero binario con il solo nodo RADICE
nodo BINRADICE(binalbero T){
 return T;
}

// Funzione FIGLIOSINISTRO
// Restituisce il figlio sinistro del nodo inserito.
nodo FIGLIOSINISTRO(nodo u){
  return u->sinistro;
}

// Funzione FIGLIODESTRO
// Restituisce il figlio destro del nodo inserito.
nodo FIGLIODESTRO(nodo u){
  return u->destro;
}

// Funzione SINISTROVUOTO
// Controlla se esiste o meno un figlio sinistro del nodo inserito.
// Restituisce 1 se è VERO, 0 se è FALSO.
int SINISTROVUOTO(nodo u){
  if(u->sinistro == NULL)
    return 1;
  else
    return 0;  
}

// Funzione DESTROVUOTO
// Controlla se esiste o meno un figlio destro del nodo inserito.
// Restituisce 1 se è VERO, 0 se è FALSO.
int DESTROVUOTO(nodo u){
  if(u->destro == NULL)
    return 1;
  else
    return 0;
}
