parent
2961104576
commit
68e37ae984
Binary file not shown.
Binary file not shown.
@ -0,0 +1,26 @@
|
||||
#CC : le compilateur a utiliser
|
||||
CC=gcc
|
||||
|
||||
#CFLAGS : les options de compilation (en C++ moderne, voir les warning,...)
|
||||
CFLAGS= -Wall -Werror -Wextra
|
||||
|
||||
SAN= -fsanitize=leak,address
|
||||
|
||||
# les fichiers sources : tous les fichiers présents dans src/
|
||||
SRC=$(wildcard src/*.c src/*.h)
|
||||
|
||||
# les fichiers objets (.o)
|
||||
OBJ=$(patsubst src/%.c,obj/%.o,$(SRC))
|
||||
|
||||
|
||||
#edition des liens : génération de l'exécutaba partir des .o
|
||||
bin/exe: $(OBJ)
|
||||
$(CC) $(OBJ) -o $@ $(SAN)
|
||||
|
||||
# génération des .a partir des .cpp et .hpporrespondants :
|
||||
obj/%.o: src/%.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
#nettoyage : destruction des .o et de l'exécutable
|
||||
clean:
|
||||
rm obj/*.o bin/exe
|
@ -0,0 +1,202 @@
|
||||
#include "graphe.h"
|
||||
|
||||
Graphe graphNouve(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Graphe adjs(Graphe g, int s)
|
||||
{
|
||||
if(vide(g))
|
||||
{
|
||||
return adjt(g, s);
|
||||
}
|
||||
if(x < g->s)
|
||||
{
|
||||
return adjt(g, s);
|
||||
}
|
||||
if(x == g -> s)
|
||||
{
|
||||
return g;
|
||||
}
|
||||
g -> suiv = adjs(g -> suiv, s);
|
||||
return g;
|
||||
}
|
||||
|
||||
Graphe adjt(Graphe g, int x)
|
||||
{
|
||||
Maillong *m;
|
||||
|
||||
m = (Maillong *)malloc(sizeof(Maillong));
|
||||
if(m == NULL)
|
||||
{
|
||||
printf("Probleme malloc adjt");
|
||||
exit(1);
|
||||
}
|
||||
m -> s = x;
|
||||
m -> suiv = g;
|
||||
m -> succ = listeNouv();
|
||||
}
|
||||
|
||||
Liste listeNouv(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vide(Graphe g)
|
||||
{
|
||||
return g == NULL;
|
||||
}
|
||||
|
||||
bool exist(Graphe g, int x)
|
||||
{
|
||||
if(vide(g))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(x < g -> s)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(x == g -> s)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return exist(g -> suiv, x);
|
||||
}
|
||||
|
||||
Graphe adja(Graphe g, int x, int y)
|
||||
{
|
||||
Maillon *aux = g;
|
||||
|
||||
if(!exist(g, x) || !exist(g, y))
|
||||
{
|
||||
return g;
|
||||
}
|
||||
while(g -> s != x)
|
||||
{
|
||||
g = g -> suiv;
|
||||
}
|
||||
g -> succ = inserer(g -> succ, y);
|
||||
return aux;
|
||||
}
|
||||
|
||||
Graphe supa(Graphe g, int x, int y)
|
||||
{
|
||||
Maillon *aux = g;
|
||||
|
||||
if(!exa(g, x, y))
|
||||
{
|
||||
return g;
|
||||
}
|
||||
while(g -> s != x)
|
||||
{
|
||||
g = g -> suiv;
|
||||
}
|
||||
g -> succ = supprimer(g -> succ, y);
|
||||
return aux;
|
||||
}
|
||||
|
||||
Graphe sups(Graphe g, int x, int y)
|
||||
{
|
||||
if(di(g, x) != 0 || de(g, x) != 0)
|
||||
{
|
||||
return g;
|
||||
}
|
||||
return sups1(Graphe g, int x);
|
||||
}
|
||||
|
||||
Graphe sups1(Graphe g, int x)
|
||||
{
|
||||
if(vide(g))
|
||||
{
|
||||
return g;
|
||||
}
|
||||
if(x < g -> s)
|
||||
{
|
||||
return g;
|
||||
}
|
||||
if(x == g -> s)
|
||||
{
|
||||
return supst(g);
|
||||
}
|
||||
g -> suiv = sups1(g -> suiv, x);
|
||||
return g;
|
||||
}
|
||||
|
||||
int de(Graphe g, int x)
|
||||
{
|
||||
if(vide(g))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(!exs(g,x))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
while(g -> v != x)
|
||||
{
|
||||
g = g -> suiv;
|
||||
}
|
||||
return longueur(g -> succ);
|
||||
}
|
||||
|
||||
int di(Graphe g, int x)
|
||||
{
|
||||
int cpt;
|
||||
|
||||
cpt = 0;
|
||||
while(!vide(g))
|
||||
{
|
||||
if(appartient(g -> succ, x))
|
||||
{
|
||||
cpt++;
|
||||
}
|
||||
g = g -> suiv;
|
||||
}
|
||||
return cpt;
|
||||
}
|
||||
|
||||
Graphe supst(Graphe g)
|
||||
{
|
||||
Maillon *m;
|
||||
|
||||
m = g;
|
||||
g = g -> suiv;
|
||||
free(m);
|
||||
return g;
|
||||
}
|
||||
|
||||
void affichage(Graphe g)
|
||||
{
|
||||
FILE *flot;
|
||||
Graphe aux = g;
|
||||
Liste l1;
|
||||
|
||||
flot = fopen("graphe.txt", "w");
|
||||
if(!flot)
|
||||
{
|
||||
printf("probleme ouverture graphe.txt");
|
||||
exit(1);
|
||||
}
|
||||
fprintf(flot, "digraph family\n");
|
||||
while(!vide(g))
|
||||
{
|
||||
fprintf(flot, "%d[label=\"%d\"]\n"g -> s, g -> s);
|
||||
g = g -> suiv;
|
||||
}
|
||||
while(!vide(aux))
|
||||
{
|
||||
while(l1 != NULL)
|
||||
{
|
||||
fprintf(flot, "%d->%d\n", aux -> s, l1 -> v);
|
||||
l1 = l1 -> suiv;
|
||||
}
|
||||
aux = aux -> suiv;
|
||||
}
|
||||
fprintf(flot, "}\n");
|
||||
fclose(flot);
|
||||
system("dotty graphe.txt");
|
||||
}
|
||||
|
||||
/*Liste fct(Graphe g, Liste e, Liste l)*/
|
@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct maillong
|
||||
{
|
||||
struct maillong *suiv;
|
||||
int s;
|
||||
Liste succ;
|
||||
} Maillong, *Graphe;
|
||||
|
||||
typedef struct maillonl
|
||||
{
|
||||
int v;
|
||||
struct maillonl *suiv;
|
||||
} Maillonl, *Liste;
|
||||
|
||||
Graphe adjs(Graphe g, int s);
|
||||
Graphe graphNouv(void);
|
||||
Graphe adjt(Graphe g, int x);
|
||||
bool vide(Graphe g);
|
||||
bool exist(Graphe g, int x);
|
||||
Graphe adja(Graphe g, int x, int y);
|
||||
Graphe supa(Graphe g, int x, int y);
|
||||
Graphe sups(Graphe g, int x, int y);
|
||||
Graphe sups(Graphe g, int x);
|
||||
int de(Graphe g, int x);
|
||||
int di(Graphe g, int x);
|
||||
Graphe supst(Graphe g);
|
||||
void affichage(Graphe g);
|
||||
|
Loading…
Reference in new issue