diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-11-21 18:37:48 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-11-21 18:37:48 +0100 |
| commit | 20fc727d4f954eb2109b71a7686c3107fdfa4bbf (patch) | |
| tree | a5613db97e67d8968c7d622b605ed530755176bb /semestre 3/structures des données/tme/tme6-11/Reseau.c | |
| parent | 341fc63ff791e08c7d0a00346080067c9bd1d5dd (diff) | |
Cours du 3 au 21 novembre
ce qui fait 3 semaines en philo et une semaine en info
Diffstat (limited to 'semestre 3/structures des données/tme/tme6-11/Reseau.c')
| -rw-r--r-- | semestre 3/structures des données/tme/tme6-11/Reseau.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/semestre 3/structures des données/tme/tme6-11/Reseau.c b/semestre 3/structures des données/tme/tme6-11/Reseau.c new file mode 100644 index 0000000..cbdaa88 --- /dev/null +++ b/semestre 3/structures des données/tme/tme6-11/Reseau.c @@ -0,0 +1,53 @@ +#include "Chaine.h" +#include <stdlib.h> +#include "Reseau.h" + +CellNoeud* initNode(Reseau* R, double x, double y){ + CellNoeud* node = (CellNoeud*) malloc(sizeof(CellNoeud)); + node->nd = (Noeud*) malloc(sizeof(Noeud)); + node->nd->num = ++R->nbNoeuds; + node->nd->x = x; + node->nd->y = y; + node->suiv = R->noeuds; + R->noeuds = node; + return node; +} + +Noeud* rechercheCreeNoeudListe(Reseau *R, double x, double y){ + CellNoeud* node = R->noeuds; + while (node && (node->nd->x != x || node->nd->y != y)) node = node->suiv; + if (node) return node->nd; + return initNode(R, x, y)->nd; +} + +Reseau* reconstitueReseauListe(Chaines *C){ + Reseau* R = (Reseau*) malloc(sizeof(Reseau)); + CellChaine* chain = C->chaines; + while (chain){ + CellPoint* points = chain->points; + CellNoeud* before; + CellNoeud* beforeTwice; + while (points){ + Noeud* node = rechercheCreeNoeudListe(R, points->x, points->y); + // represents voisins of node + CellNoeud* cellNode = (CellNoeud*) malloc(sizeof(CellNoeud)); + cellNode->nd = node; + cellNode->suiv = NULL; + if (beforeTwice){ + CellNoeud* cell = (CellNoeud*) malloc(sizeof(CellNoeud)); + cell->nd = node; + cell->suiv = NULL; + beforeTwice->suiv = cell; // link beforeTwice to current + before->nd->voisins = beforeTwice; // set before voisins + } + beforeTwice = before; + before = cellNode; + points = points->suiv; + } + if (beforeTwice && before){ + before->nd->voisins = beforeTwice; // set before voisins + } + chain = chain->suiv; + } + return R; +} |
