examen fini
This commit is contained in:
parent
0f0c9a48dc
commit
9ee8f961b3
9
examen/T1/Makefile
Normal file
9
examen/T1/Makefile
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
CC = gcc
|
||||||
|
|
||||||
|
all: main
|
||||||
|
|
||||||
|
main:
|
||||||
|
$(CC) *.c *.h
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm a.out
|
52
examen/T1/StatistiqueFichier.c
Normal file
52
examen/T1/StatistiqueFichier.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#include "StatistiqueFichier.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
ASCII_table init_table()
|
||||||
|
{
|
||||||
|
ASCII_table table;
|
||||||
|
for (int i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
table.ASCII[i] = 0;
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_ASCII_table(ASCII_table *table)
|
||||||
|
{
|
||||||
|
for (int i = 32; i <= 126; i++)
|
||||||
|
{
|
||||||
|
printf("%d ", table->ASCII[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_StatistiqueResultats(ASCII_table *table)
|
||||||
|
{
|
||||||
|
for (int i = 32; i <= 126; i++)
|
||||||
|
{
|
||||||
|
if (table->ASCII[i])
|
||||||
|
{
|
||||||
|
printf("%c: %d\n", i, table->ASCII[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ASCII_table *StatistiqueFichier(char *nomFichier, ASCII_table *table)
|
||||||
|
{
|
||||||
|
FILE *pFile;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
if (pFile = fopen(nomFichier, "rt"))
|
||||||
|
{
|
||||||
|
for (c = fgetc(pFile); !feof(pFile); c = fgetc(pFile))
|
||||||
|
{
|
||||||
|
table->ASCII[(int)c]++;
|
||||||
|
}
|
||||||
|
fclose(pFile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("error");
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
}
|
9
examen/T1/StatistiqueFichier.h
Normal file
9
examen/T1/StatistiqueFichier.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
typedef struct ASCII_table
|
||||||
|
{
|
||||||
|
int ASCII[256];
|
||||||
|
} ASCII_table;
|
||||||
|
|
||||||
|
ASCII_table init_table();
|
||||||
|
ASCII_table *StatistiqueFichier(char *nomFichier, ASCII_table *table);
|
||||||
|
void print_ASCII_table(ASCII_table *table);
|
||||||
|
void print_StatistiqueResultats(ASCII_table *table);
|
8
examen/T1/fichier.txt
Normal file
8
examen/T1/fichier.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
abcdefg
|
||||||
|
abcdefg
|
||||||
|
abcdefg
|
||||||
|
abcdefg
|
||||||
|
,/df,glsd,lrekg
|
||||||
|
}{}:":L:
|
||||||
|
sdkljflskjdflkajlk. fdjsakljflwa
|
||||||
|
jgriej. giojgrekrjkdskjfklwjk
|
11
examen/T1/main.c
Normal file
11
examen/T1/main.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "StatistiqueFichier.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
ASCII_table table;
|
||||||
|
table = init_table();
|
||||||
|
StatistiqueFichier("fichier.txt", &table);
|
||||||
|
print_StatistiqueResultats(&table);
|
||||||
|
return 0;
|
||||||
|
}
|
9
examen/T2/Makefile
Normal file
9
examen/T2/Makefile
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
CC = gcc
|
||||||
|
|
||||||
|
all: main
|
||||||
|
|
||||||
|
main:
|
||||||
|
$(CC) *.c *.h
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm a.out
|
67
examen/T2/arbres_binaires.c
Normal file
67
examen/T2/arbres_binaires.c
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#include "arbres_binaires.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
SNoeud CreerFeuille(float valeur, char lettre)
|
||||||
|
{
|
||||||
|
SNoeud feuille;
|
||||||
|
feuille.valeur = valeur;
|
||||||
|
feuille.est_feuille = true;
|
||||||
|
feuille.lettre = lettre;
|
||||||
|
return feuille;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNoeud_Array *CreerNoeudArray(valeur_lettre *t, int taille)
|
||||||
|
{
|
||||||
|
SNoeud_Array *tableau = malloc(sizeof(SNoeud_Array));
|
||||||
|
tableau->noeud = malloc(sizeof(SNoeud) * taille);
|
||||||
|
tableau->taille = taille;
|
||||||
|
for (int i = 0; i < taille; i++)
|
||||||
|
{
|
||||||
|
tableau->noeud[i] = CreerFeuille(t[i].valeur, t[i].lettre);
|
||||||
|
}
|
||||||
|
return tableau;
|
||||||
|
}
|
||||||
|
|
||||||
|
deux_Noeuds find2min(SNoeud_Array *tableau)
|
||||||
|
{
|
||||||
|
deux_Noeuds min;
|
||||||
|
min.gauche = NULL;
|
||||||
|
min.droite = NULL;
|
||||||
|
int min1 = 0;
|
||||||
|
int min2 = 0;
|
||||||
|
for (int i = 0; i < tableau->taille; i++)
|
||||||
|
{
|
||||||
|
if (tableau->noeud[i].valeur < min1)
|
||||||
|
{
|
||||||
|
min2 = min1;
|
||||||
|
min1 = tableau->noeud[i].valeur;
|
||||||
|
min.droite = min.gauche;
|
||||||
|
min.gauche = &tableau->noeud[i];
|
||||||
|
}
|
||||||
|
else if (tableau->noeud[i].valeur < min2)
|
||||||
|
{
|
||||||
|
min2 = tableau->noeud[i].valeur;
|
||||||
|
min.droite = &tableau->noeud[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNoeud AssocierNoeud(SNoeud gauche, SNoeud droite)
|
||||||
|
{
|
||||||
|
SNoeud noeud;
|
||||||
|
noeud.valeur = gauche.valeur + droite.valeur;
|
||||||
|
noeud.est_feuille = false;
|
||||||
|
noeud.gauche = &gauche;
|
||||||
|
noeud.droite = &droite;
|
||||||
|
return noeud;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNoeud EtapeGlouton(SNoeud_Array *tableau)
|
||||||
|
{
|
||||||
|
deux_Noeuds min = find2min(tableau);
|
||||||
|
SNoeud noeud = AssocierNoeud(*min.gauche, *min.droite);
|
||||||
|
free(min.gauche);
|
||||||
|
free(min.droite);
|
||||||
|
return noeud;
|
||||||
|
}
|
34
examen/T2/arbres_binaires.h
Normal file
34
examen/T2/arbres_binaires.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
typedef struct SNoeud
|
||||||
|
{
|
||||||
|
float valeur;
|
||||||
|
bool est_feuille;
|
||||||
|
char lettre;
|
||||||
|
struct SNoeud *gauche;
|
||||||
|
struct SNoeud *droite;
|
||||||
|
} SNoeud;
|
||||||
|
|
||||||
|
typedef struct SNoeud_Array
|
||||||
|
{
|
||||||
|
SNoeud *noeud;
|
||||||
|
int taille;
|
||||||
|
} SNoeud_Array;
|
||||||
|
|
||||||
|
typedef struct deux_Noeuds
|
||||||
|
{
|
||||||
|
SNoeud *gauche;
|
||||||
|
SNoeud *droite;
|
||||||
|
} deux_Noeuds;
|
||||||
|
|
||||||
|
typedef struct valeur_lettre
|
||||||
|
{
|
||||||
|
float valeur;
|
||||||
|
char lettre;
|
||||||
|
} valeur_lettre;
|
||||||
|
|
||||||
|
SNoeud_Array *CreerNoeudArray(valeur_lettre* t, int taille);
|
||||||
|
deux_Noeuds find2min(SNoeud_Array *tableau);
|
||||||
|
SNoeud EtapeGlouton(SNoeud_Array *tableau);
|
||||||
|
SNoeud CreerFeuille(float valeur, char lettre);
|
||||||
|
SNoeud AssocierNoeud(SNoeud gauche, SNoeud droite);
|
8
examen/T2/main.c
Normal file
8
examen/T2/main.c
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "arbres_binaires.h"
|
||||||
|
|
||||||
|
int main(int argc, char const *argv[])
|
||||||
|
{
|
||||||
|
valeur_lettre vl[6] = {{0.05, 'F'}, {0.1, 'A'}, {0.1, 'B'}, {0.15, 'D'}, {0.25, 'C'}, {0.35, 'E'}};
|
||||||
|
SNoeud_Array *arr = CreerNoeudArray(vl, 6);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user