First Commit

This commit is contained in:
Yûki 2019-12-07 18:26:56 +01:00 committed by GitHub
parent 3f207ccdd3
commit 74f6b061ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 435 additions and 0 deletions

View file

@ -0,0 +1,19 @@
CC = gcc
CCOPTS = -Wall
all: main
arbre_naire.o: arbre_naire.c arbre_naire.h
${CC} ${CCOPTS} -c arbre_naire.c
arbre_binaire.o: arbre_binaire.c arbre_binaire.h
${CC} ${CCOPTS} -c arbre_binaire.c
main.o: main.c
${CC} ${CCOPTS} -c main.c
main: main.o arbre_naire.o arbre_binaire.o
${CC} ${CCOPTS} -o main main.o arbre_naire.o arbre_binaire.o
clean:
rm *.o ; rm main

View file

@ -0,0 +1,69 @@
#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);
}
}

View file

@ -0,0 +1,25 @@
#ifndef __ARBRE_BINAIRE__
#define __ARBRE_BINAIRE__
typedef char Elt;
typedef int bool;
struct znoeud {
Elt elt ;
int poids;
struct znoeud *fils_gauche;
struct znoeud *fils_droit;
};
typedef struct znoeud noeud ;
typedef struct znoeud * arbre;
arbre creer_arbre_vide(void);
arbre creer_arbre_huffman(Elt e, int p, arbre fg, arbre fd);
arbre fils_gauche(arbre a);
arbre fils_droit(arbre a);
Elt racine(arbre a);
bool est_arbre_vide(arbre a);
arbre creer_feuille(Elt e) ;
bool est_feuille(arbre a) ;
#endif

View file

@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
struct zoccurence{
int nb;
char lettre;
};
typedef struct zoccurence occ;
typedef struct zoccurence * freq;

View file

@ -0,0 +1,24 @@
#include <stdio.h>
#include "arbre_binaire.h"
struct zoccurence{
int nb;
char lettre;
};
typedef struct zoccurence occ;
typedef struct zoccurence * freq;
int main ()
{
}
/*
L est considéré comme ordonné
*/
arbre huffman(arbre H, freq L[])
{
int i;
printf(L[]->nb);
printf(L[]->lettre);
}