Add FILE ORGANIZATION FROM THE START

This commit is contained in:
NyxiumYuuki 2019-12-07 20:39:59 +01:00
parent 1795f0287b
commit 43b0081d65
No known key found for this signature in database
GPG key ID: 03E8F3CF3183323A
16 changed files with 95 additions and 67 deletions

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

56
arbre_de_codage/liste.c Normal file
View file

@ -0,0 +1,56 @@
#include <assert.h>
#include <stdlib.h>
#include "liste.h"
Freq creer_liste_vide(){
return NULL;
}
int est_liste_vide(Freq l){
return(l==NULL);
}
Freq ajouter(int nb, char lettre, Freq l){
Occ * tmp;
tmp=malloc(sizeof(Occ));
tmp->nb=nb;
tmp->lettre=lettre;
tmp->suiv=l;
return tmp;
}
char tete(Freq l){
assert(!est_liste_vide(l));
return(l->lettre);
}
Freq queue(Freq l){
assert(!est_liste_vide(l));
return(l->suiv);
}
void liberer_liste(Freq l){
if(!est_liste_vide(l)){
liberer_liste(queue(l));
free(l);
}
}
Freq liberer_maillon(Freq l){
assert(!est_liste_vide(l));
Occ * tmp = l->suiv;
free(l);
return tmp;
}
int rechercher(char lettre,Freq l){
if(est_liste_vide(l)){
return 0;
}
else if(lettre==tete(l)){
return 1;
}
else{
return rechercher(lettre,queue(l));
}
}

20
arbre_de_codage/liste.h Normal file
View file

@ -0,0 +1,20 @@
#ifndef __LISTE_OCCURENCE__
#define __LISTE_OCCURENCE__
struct zoccurence{
int nb;
char lettre;
struct zoccurence *suiv;
};
typedef struct zoccurence Occ;
typedef struct zoccurence * Freq;
Freq creer_liste_vide();
int est_liste_vide(Freq l);
Freq ajouter(int nb, char lettre, Freq l);
int tete(Freq l);
Freq queue(Freq l);
void liberer_liste(Freq l);
Freq liberer_maillon(Freq l);
int rechercher(char lettre, Freq l);
#endif