merci Titouan <3

master
esterfreyja 2 years 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" #include "graphe.h"
Graphe graphNouve(void) Graphe graphNouv()
{ {
return NULL; return NULL;
} }
Graphe adjs(Graphe g, int s) Graphe adjst(Graphe g, int x)
{ {
if(vide(g)) MaillonG *m;
{
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)); m = (MaillonG*)malloc(sizeof(MaillonG));
if(m == NULL) if(m == NULL)
{ {
printf("Probleme malloc adjt"); printf("probleme malloc MaillonG\n");
exit(1); exit(1);
} }
m -> s = x; m->v = x;
m->suiv = g; m->suiv = g;
m -> succ = listeNouv(); 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)
bool vide(Graphe g) return adjst(g, x);
{ if(x == g->v)
return g == NULL; return g;
} g->suiv = adjs(g->suiv, x);
return g;
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) Graphe adja(Graphe g, int x, int y)
{ {
Maillon *aux = g; Graphe m;
if(!exist(g, x) || !exist(g, y)) m = g;
{ if(!exs(g, x) || !exs(g, y))
return g; return g;
} while(g->v != x)
while(g -> s != x)
{
g = g->suiv; g = g->suiv;
} g->l = insList(g->l, y);
g -> succ = inserer(g -> succ, y); return m;
return aux;
} }
Graphe supa(Graphe g, int x, int y) Graphe sups1(Graphe g, int x)
{ {
Maillon *aux = g; Graphe m;
if(!exa(g, x, y)) if(g->v == x)
{
return g;
}
while(g -> s != x)
{ {
m = g;
g = g->suiv; g = g->suiv;
free(m);
return g;
} }
g -> succ = supprimer(g -> succ, y); g->suiv = sups1(g->suiv, x);
return aux; return g;
} }
Graphe sups(Graphe g, int x, int y) Graphe sups(Graphe g, int x)
{
if(di(g, x) != 0 || de(g, x) != 0)
{ {
if(!exs(g, x) || de(g, x) != 0 || di(g, x) != 0)
return g; return g;
} return sups1(g, x);
return sups1(Graphe g, int x);
} }
Graphe sups1(Graphe g, int x) Graphe supa(Graphe g, int x, int y)
{
if(vide(g))
{ {
Graphe m;
m = g;
if(!exa(g, x, y))
return g; return g;
while(g->v != x)
g = g->suiv;
g->l = supList(g->l, y);
return m;
} }
if(x < g -> s)
bool exs(Graphe g, int s)
{ {
return g; if(videGraphe(g))
return false;
if(s < g->v)
return false;
if(s == g->v)
return true;
return exs(g->suiv, s);
} }
if(x == g -> s)
bool exa(Graphe g, int x, int y)
{ {
return supst(g); if(!exs(g, x) || !exs(g, y))
} return false;
g -> suiv = sups1(g -> suiv, x); while(g->v != x)
return g; g = g->suiv;
return rechList(g->l, y);
} }
int de(Graphe g, int x) int de(Graphe g, int x)
{ {
if(vide(g)) while(!videGraphe(g))
{
return 0;
}
if(!exs(g,x))
{
return 0;
}
while(g -> v != x)
{ {
if(g->v == x)
return lgList(g->l);
g = g->suiv; g = g->suiv;
} }
return longueur(g -> succ); return 0;
} }
int di(Graphe g, int x) int di(Graphe g, int x)
@ -146,57 +119,87 @@ int di(Graphe g, int x)
int cpt; int cpt;
cpt = 0; cpt = 0;
while(!vide(g)) while(!videGraphe(g))
{
if(appartient(g -> succ, x))
{ {
if(rechList(g->l, x))
cpt++; cpt++;
}
g = g->suiv; g = g->suiv;
} }
return cpt; 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; bool videGraphe(Graphe g)
{
return g == NULL;
}
Liste esuc(Graphe g, int x)
{
if(!exs(g, x))
return listenouv();
while(g->v != x)
g = g->suiv; g = g->suiv;
free(m); return g->l;
return g;
} }
void affichage(Graphe g) Liste parcoursProfondeur(Graphe g, Liste e, Liste l)
{ {
FILE *flot; int k;
Graphe aux = g;
Liste l1; 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"); flot = fopen("graphe.txt", "w");
if(!flot) if(flot == NULL)
{ {
printf("probleme ouverture graphe.txt"); printf("probleme ouverture fichier affichage graphe\n");
exit(1); exit(1);
} }
fprintf(flot, "digraph family\n"); fprintf(flot, "digraph family\n{\n");
while(!vide(g)) while(!videGraphe(g))
{ {
fprintf(flot, "%d[label=\"%d\"]\n"g -> s, g -> s); fprintf(flot, "%d[label=\"S%d\"]\n", g->v, g->v);
g = g->suiv; 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); fprintf(flot, "%d->%d\n", m->v, aux->v);
l1 = l1 -> suiv;
}
aux = aux->suiv; aux = aux->suiv;
} }
m = m->suiv;
}
fprintf(flot, "}\n"); fprintf(flot, "}\n");
fclose(flot); fclose(flot);
system("dotty graphe.txt"); 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 <stdbool.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include "liste.h"
typedef struct maillong typedef struct maillonG
{
struct maillong *suiv;
int s;
Liste succ;
} Maillong, *Graphe;
typedef struct maillonl
{ {
int v; int v;
struct maillonl *suiv; struct maillonG *suiv;
} Maillonl, *Liste; Liste l;
} MaillonG, *Graphe;
Graphe adjs(Graphe g, int s); Graphe graphNouv();
Graphe graphNouv(void); Graphe adjst(Graphe g, int x);
Graphe adjt(Graphe g, int x); Graphe adjs(Graphe g, int x);
bool vide(Graphe g);
bool exist(Graphe g, int x);
Graphe adja(Graphe g, int x, int y); Graphe adja(Graphe g, int x, int y);
Graphe supa(Graphe g, int x, int y); Graphe sups1(Graphe g, int x);
Graphe sups(Graphe g, int x, int y);
Graphe sups(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 de(Graphe g, int x);
int di(Graphe g, int x); int di(Graphe g, int x);
Graphe supst(Graphe g); Liste esg(Graphe g/*, int x*/);
void affichage(Graphe g); 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) Liste listenouv(void)
{ {
@ -18,7 +18,7 @@ Liste insTList(Liste l, int x)
maill = (Maillon*)malloc(sizeof(Maillon)); maill = (Maillon*)malloc(sizeof(Maillon));
if(maill == NULL) if(maill == NULL)
{ {
printf("Pb malloc\n"); printf("Probleme malloc Maillon Liste\n");
exit(1); exit(1);
} }
maill->v = x; maill->v = x;
@ -44,7 +44,7 @@ Liste supTList(Liste l)
if(videList(l)) if(videList(l))
{ {
printf("Opération interdite\n"); printf("Opération interdite suppression tete liste\n");
exit(1); exit(1);
} }
aux = l; aux = l;
@ -69,7 +69,7 @@ int tList(Liste l)
{ {
if(videList(l)) if(videList(l))
{ {
printf("Opération interdite\n"); printf("Opération interdite tListe\n");
exit(1); exit(1);
} }
return l->v; return l->v;

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