1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
typedef struct Snoeud {
char *nom;
struct Slistnoeuds *listadj;
struct Snoeud *suivant;
int couleur;
} Tnoeud;
typedef struct Smaillon {
Tnoeud *noeud;
struct Smaillon *suivant;
} Tmaillon, Tadjacent, Telement;
typedef struct Slistnoeuds {
struct Smaillon *maillon;
int taille;
} Tlistnoeuds, Tlistadj, Tpartition;
Tnoeud nouveau_noeud() {
// malloc(sizeof(Tnoeud)) etc
};
Tmaillon nouveau_maillon() {
// malloc(sizeof(Tmaillon)) etc
};
void ajouter_maillon(Tlistnoeuds *l, Tnoeud *n) {
if (l->maillon == NULL) l->maillon=nouveau_maillon(n);
else {
Tmaillon *tete=nouveau_maillon(n);
tete->suivant=l->maillon;
l->maillon=tete;
}
l->taille++;
};
void vider_listnoeuds(Tlistnoeuds * l) {
Tmaillon *iterator=l->maillon;
Tmaillon *suivant;
while (iterator != NULL) {
suivant=iterator->suivant;
free(iterator);
iterator=suivant;
}
l->maillon= NULL;
l->taille= 0;
}
void exemple(void) {
int taille=5;
Tnoeud *n=nouveau_noeud("arf");
Tpartition * blanc;
Tpartition * noir;
blanc= (Tpartition *) calloc(taille,sizeof(Tpartition));
noir= (Tpartition *) calloc(taille,sizeof(Tpartition));
ajouter_maillon(&blanc[0],n); // <- fonctionne
vider_listnoeuds(&blanc[0]);
ajouter_maillon(&blanc[0],n); // <- plantage
}; |
Partager