C > Arbre init p2

TitreArbre init p2
Postée le29-11-2010
Affichée343
Mini-lien
Description

Arbre de recherche suite

EtatContient des erreurs. Contient des erreurs.
Code d'insertion
Options
Afficher les numéros de lignes  Mettre la source en plein ecran  Selectionner la source  Partager sur Facebook 
Téléchargement Telecharger en format txt  Telecharger en format pdf  Telecharger en format c
Plein ecran
typedef struct noeud{
        int donnee;
        struct noeud * fg;
        struct noeud * fd;
}*Arbre;

Arbre initArbre(){
        Arbre a;
        a==NULL;
}
int videArbre(Arbre a){
        return a==NULL;
}

int DonneeArbre(Arbre a){
        return a->donnee;
}

Arbre FilsGauche(Arbre a){
        return a->fg;
}

Arbre FilsDroit(Arbre a){
        return a->fd;
}

int Feuille(Arbre a){
        if (FilsDroit(a)==NULL&&FilsGauche(a)==NULL) {
                return 1;
        }
        else return 0;
}

Arbre creatFeuille(int elt){
        Arbre a;
        a=(Arbre)malloc(sizeof(struct noeud));
        a->donnee=elt;
        a->fg=NULL;
        a->fd=NULL;
        return a;
}

Arbre creatNoeud(int elt, Arbre filsg, Arbre filsd){
        Arbre nd;
        nd=(Arbre)malloc(sizeof(struct noeud));
        nd->donnee=elt;
        nd->fg=filsg;
        nd->fd=filsd;
        return nd;
}
void insertEltArbreRech(Arbre a, int elt){
        if (videArbre(a)) {
                a=creatFeuille(elt);
        }
        else {
                if (elt<=DonneeArbre(a)){
                        insertEltArbreRech(FilsGauche(a), elt);
                }
                else {
                        insertEltArbreRech(FilsDroit(a), elt);
                }

        }
}