This repository has been archived on 2026-05-01. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Projet-C-Huffman/Yûki/arbre_de_codage/arbre_binaire.c
2019-12-07 18:26:56 +01:00

69 lines
No EOL
1.1 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "arbre_binaire.h"
arbre creer_arbre_vide (void)
{
return NULL ;
}
arbre creer_arbre_huffman(Elt e, int p, arbre fg, arbre fd)
{
noeud * tmp = malloc(sizeof(noeud));
tmp->elt=e;
tmp->poids=p;
tmp->fils_gauche=fg;
tmp->fils_droit=fd;
return tmp;
}
arbre fils_gauche(arbre a)
{
assert(!est_arbre_vide(a));
return a->fils_gauche;
}
arbre fils_droit(arbre b)
{
assert(!est_arbre_vide(b));
return b->fils_droit;
}
Elt racine(arbre a)
{
assert(!est_arbre_vide(a));
return a->elt;
}
bool est_arbre_vide(arbre a)
{
return (a == NULL) ;
}
arbre creer_feuille(Elt e)
{
return creer_arbre(e, creer_arbre_vide(), creer_arbre_vide()) ;
}
bool est_feuille(arbre a)
{
if (est_arbre_vide(a))
return 0 ;
return (est_arbre_vide(a->fils_gauche) && est_arbre_vide(a->fils_droit)) ;
}
void free_noeud(arbre a)
{
assert(!est_arbre_vide(a));
free(a);
}
void free_arbre(arbre a)
{
if(!est_arbre_vide(a)){
free_arbre(fils_gauche(a));
free_arbre(fils_droit(a));
free(a);
}
}