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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| typedef struct test {
int **mat;
int x;
int y;
int c;
struct test *prec;
} test_t;
static void mat_free (int ** mat)
{
for (int i = 0; i < TAILLE; i++)
free (mat[i]);
free (mat);
}
static void pile_free(test_t *pile)
{
if (pile != NULL)
{
if (pile->prec != NULL)
pile_free(pile->prec);
mat_free(pile->mat);
free(pile);
}
}
int** mat_copy (int **mat)
{
int **cpy = mat_alloc();
for (int i = 0 ; i < TAILLE ; i++)
memcpy (cpy[i], mat [i], TAILLE * sizeof (int));
return cpy;
}
test_t *push(test_t *pile, int ***mat)
{
test_t *elem_prec = malloc(sizeof(test_t));
elem_prec->mat=mat_copy(*mat);
/*******************************************************
divers calculs pour trouver le x, y et c de la structure
********************************************************/
elem_prec->x = x;
elem_prec->y = y;
elem_prec->c = c;
if (pile == NULL)
elem_prec->prec = NULL;
else
elem_prec->prec = pile;
pile = elem_prec;
(*mat)[pile->x][pile->y] = pile->c;
return pile;
}
test_t *pile = NULL;
bool f (int **mat)
{
switch (test_mat(mat)) //divers calculs qui vont modifiés 'mat' et renvoyés un entier
{
case (0) :
pile_free(pile);
return 0;
case (1) :
pile = push(pile, &(mat));
return f(mat);
default :
return 1;
}
return 1;
} |
Partager