merci Titouan <3

master
esterfreyja 1 year ago
parent 006e2ca09e
commit 394ec0283e

Binary file not shown.

@ -0,0 +1,12 @@
digraph family
{
6[label="S6"]
8[label="S8"]
9[label="S9"]
15[label="S15"]
23[label="S23"]
6->15
9->8
9->15
23->15
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1,144 +1,117 @@
#include "graphe.h"
Graphe graphNouve(void)
Graphe graphNouv()
{
return NULL;
}
Graphe adjs(Graphe g, int s)
Graphe adjst(Graphe g, int x)
{
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;
MaillonG *m;
m = (Maillong *)malloc(sizeof(Maillong));
m = (MaillonG*)malloc(sizeof(MaillonG));
if(m == NULL)
{
printf("Probleme malloc adjt");
printf("probleme malloc MaillonG\n");
exit(1);
}
m -> s = x;
m -> suiv = g;
m -> succ = listeNouv();
m->v = x;
m->suiv = g;
m->l = listenouv();
return m;
}
Liste listeNouv(void)
Graphe adjs(Graphe g, int x)
{
return NULL;
if(videGraphe(g))
return adjst(g, x);
if(x < g->v)
return adjst(g, x);
if(x == g->v)
return g;
g->suiv = adjs(g->suiv, x);
return g;
}
bool vide(Graphe g)
Graphe adja(Graphe g, int x, int y)
{
return g == NULL;
Graphe m;
m = g;
if(!exs(g, x) || !exs(g, y))
return g;
while(g->v != x)
g = g->suiv;
g->l = insList(g->l, y);
return m;
}
bool exist(Graphe g, int x)
Graphe sups1(Graphe g, int x)
{
if(vide(g))
{
return false;
}
if(x < g -> s)
{
return false;
}
if(x == g -> s)
Graphe m;
if(g->v == x)
{
return true;
m = g;
g = g->suiv;
free(m);
return g;
}
return exist(g -> suiv, x);
g->suiv = sups1(g->suiv, x);
return g;
}
Graphe adja(Graphe g, int x, int y)
Graphe sups(Graphe g, int x)
{
Maillon *aux = g;
if(!exist(g, x) || !exist(g, y))
{
if(!exs(g, x) || de(g, x) != 0 || di(g, x) != 0)
return g;
}
while(g -> s != x)
{
g = g -> suiv;
}
g -> succ = inserer(g -> succ, y);
return aux;
return sups1(g, x);
}
Graphe supa(Graphe g, int x, int y)
{
Maillon *aux = g;
Graphe m;
m = g;
if(!exa(g, x, y))
{
return g;
}
while(g -> s != x)
{
g = g -> suiv;
}
g -> succ = supprimer(g -> succ, y);
return aux;
while(g->v != x)
g = g->suiv;
g->l = supList(g->l, y);
return m;
}
Graphe sups(Graphe g, int x, int y)
bool exs(Graphe g, int s)
{
if(di(g, x) != 0 || de(g, x) != 0)
{
return g;
}
return sups1(Graphe g, int x);
if(videGraphe(g))
return false;
if(s < g->v)
return false;
if(s == g->v)
return true;
return exs(g->suiv, s);
}
Graphe sups1(Graphe g, int x)
bool exa(Graphe g, int x, int y)
{
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;
if(!exs(g, x) || !exs(g, y))
return false;
while(g->v != x)
g = g->suiv;
return rechList(g->l, y);
}
int de(Graphe g, int x)
{
if(vide(g))
while(!videGraphe(g))
{
return 0;
if(g->v == x)
return lgList(g->l);
g = g->suiv;
}
if(!exs(g,x))
{
return 0;
}
while(g -> v != x)
{
g = g -> suiv;
}
return longueur(g -> succ);
}
int di(Graphe g, int x)
@ -146,57 +119,87 @@ int di(Graphe g, int x)
int cpt;
cpt = 0;
while(!vide(g))
{
if(appartient(g -> succ, x))
while(!videGraphe(g))
{
if(rechList(g->l, x))
cpt++;
}
g = g -> suiv;
g = g->suiv;
}
return cpt;
}
Graphe supst(Graphe g)
Liste esg(Graphe g/*, int x*/)
{
Maillon *m;
Liste res = listenouv();
if(videGraphe(g))
return res;
while(g != NULL)
{
res = insList(res, g->v);
g = g->suiv;
}
return res;
}
m = g;
g = g -> suiv;
free(m);
return g;
bool videGraphe(Graphe g)
{
return g == NULL;
}
void affichage(Graphe g)
Liste esuc(Graphe g, int x)
{
FILE *flot;
Graphe aux = g;
if(!exs(g, x))
return listenouv();
while(g->v != x)
g = g->suiv;
return g->l;
}
Liste parcoursProfondeur(Graphe g, Liste e, Liste l)
{
int k;
Liste l1;
if(videList(e))
return l;
k = tList(e);
if(rechList(l, k))
l1 = l;
else
l1 = parcoursProfondeur(g, esuc(g, k), insList(l, k));
return parcoursProfondeur(g, supList(e, k), l1);
}
void afficherGraphe(Graphe g)
{
FILE *flot;
Graphe m;
Liste aux;
m = g;
flot = fopen("graphe.txt", "w");
if(!flot)
if(flot == NULL)
{
printf("probleme ouverture graphe.txt");
printf("probleme ouverture fichier affichage graphe\n");
exit(1);
}
fprintf(flot, "digraph family\n");
while(!vide(g))
fprintf(flot, "digraph family\n{\n");
while(!videGraphe(g))
{
fprintf(flot, "%d[label=\"%d\"]\n"g -> s, g -> s);
g = g -> suiv;
fprintf(flot, "%d[label=\"S%d\"]\n", g->v, g->v);
g = g->suiv;
}
while(!vide(aux))
while(!videGraphe(m))
{
while(l1 != NULL)
aux = m->l;
while(aux != NULL)
{
fprintf(flot, "%d->%d\n", aux -> s, l1 -> v);
l1 = l1 -> suiv;
fprintf(flot, "%d->%d\n", m->v, aux->v);
aux = aux->suiv;
}
aux = aux -> suiv;
m = m->suiv;
}
fprintf(flot, "}\n");
fclose(flot);
system("dotty graphe.txt");
}
/*Liste fct(Graphe g, Liste e, Liste l)*/

@ -1,31 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include "liste.h"
typedef struct maillong
{
struct maillong *suiv;
int s;
Liste succ;
} Maillong, *Graphe;
typedef struct maillonl
typedef struct maillonG
{
int v;
struct maillonl *suiv;
} Maillonl, *Liste;
struct maillonG *suiv;
Liste l;
} MaillonG, *Graphe;
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 graphNouv();
Graphe adjst(Graphe g, int x);
Graphe adjs(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 sups1(Graphe g, int x);
Graphe sups(Graphe g, int x);
Graphe supa(Graphe g, int x, int y);
bool exs(Graphe g, int s);
bool exa(Graphe g, int x, int y);
int de(Graphe g, int x);
int di(Graphe g, int x);
Graphe supst(Graphe g);
void affichage(Graphe g);
Liste esg(Graphe g/*, int x*/);
bool videGraphe(Graphe g);
Liste esuc(Graphe g, int x);
Liste parcoursProfondeur(Graphe g, Liste e, Liste l);
void afficherGraphe(Graphe g);

@ -1,4 +1,4 @@
#include "graph.h"
#include "liste.h"
Liste listenouv(void)
{
@ -18,7 +18,7 @@ Liste insTList(Liste l, int x)
maill = (Maillon*)malloc(sizeof(Maillon));
if(maill == NULL)
{
printf("Pb malloc\n");
printf("Probleme malloc Maillon Liste\n");
exit(1);
}
maill->v = x;
@ -44,7 +44,7 @@ Liste supTList(Liste l)
if(videList(l))
{
printf("Opération interdite\n");
printf("Opération interdite suppression tete liste\n");
exit(1);
}
aux = l;
@ -69,7 +69,7 @@ int tList(Liste l)
{
if(videList(l))
{
printf("Opération interdite\n");
printf("Opération interdite tListe\n");
exit(1);
}
return l->v;

@ -3,22 +3,12 @@
#include <stddef.h>
#include <stdio.h>
typedef struct maillon
{
int v;
struct maillon *suiv;
} Maillon, *Liste;
typedef struct maillonG
{
int v;
struct maillonG *suiv;
Liste l;
} MaillonG, *Graphe;
Liste listenouv (void);
bool videList (Liste l);
Liste insTList (Liste l, int x);

@ -0,0 +1,79 @@
#include "graphe.h"
void testList()
{
Liste l = listenouv();
l = insList(l, 3);
l = insList(l, 5);
l = insList(l, 1);
l = insList(l, 9);
l = insList(l, 20);
l = insList(l, 7);
afficherList(l);
l = supList(l, 1);
l = supList(l, 4);
l = supList(l, 9);
afficherList(l);
printf("Valeur en tete %d => 3\n", tList(l));
if(rechList(l, 1))
printf("Rech marche pas\n");
else
printf("Rech marche\n");
if(rechList(l, 20))
printf("Rech marche\n");
else
printf("Rech marche pas\n");
printf("lgList %d => 4\n", lgList(l));
}
void testGraphe()
{
Graphe g = graphNouv();
g = adjs(g, 3);
g = adjs(g, 6);
// g = adjs(g, 3); marche pas (normal)
g = adjs(g, 9);
g = adjs(g, 8);
g = adjs(g, 15);
g = adjs(g, 23);
if(exs(g, 3))
printf("exs marche\n");
else
printf("exs marche pas \n");
if(exs(g, 415))
printf("exs marche pas\n");
else
printf("exs marche\n");
g = adja(g, 3, 6);
g = adja(g, 6, 15);
g = adja(g, 9, 8);
g = adja(g, 9, 6);
g = adja(g, 9, 15);
g = adja(g, 23, 15);
// Test existe
// if(exa(g, 3, 5))
// printf("exa marche pas\n");
// else
// printf("exa marche\n");
// if(exa(g, 3, 6))
// printf("exa marche\n");
// else
// printf("exa marche pas\n");
afficherGraphe(g);
g = supa(g, 9, 6);
afficherGraphe(g);
// g = sups(g, 15); fonctionne pas (normal)
g = supa(g, 3, 6);
g = sups(g, 3);
afficherGraphe(g);
afficherList(esg(g));
}
int main(void)
{
//testList();
testGraphe();
return 0;
}
Loading…
Cancel
Save