Salut !

Je voulais faire un programme en C qui fait la création d'un arbre qui à comme racine un noeud qui à un tableau de 9 entiers (etat initial ) et ces successeurs represente les permutation possible de 0 sachant que 0 peut faire une permutation qu'avec les cases adjascentes;

voila le code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#include<stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
 
/******************************************************************************/
//structure liste entier
struct elt {
****int val ;
****struct elt *suiv ;
};
typedef struct elt* liste;
 
 
/* Création d'un nouvel élément */
liste creation(int vval)
{    liste e = NULL ;
    e = (liste) malloc(sizeof(struct elt*));
    if(e!=NULL) {
        e->val = vval ;
        e->suiv = NULL ;
    }
    return e ;
}
/*vide ab */
int vide_l_int(liste* l)
{    liste q = *l ;
    return(q==NULL);
}
/* insert en queue */
void enfiler_l_int(liste* l,int ve)
{   liste* e=NULL,q = *l ; ;
    e=creation(ve);
 
    if(q==NULL) {*l =e;}
    else {
 
       while(q->suiv!=NULL) q = q->suiv ;
        q->suiv = e ;
    }
}
 
 
 
/*xxxxxxxxxxxx DENILER UN NOEUD DANS LA liste xxxxxxxx*/
liste defiler_l_int(liste* l)
{
liste p=*l, q=p->suiv;
if(p!=NULL){
             l=q;
            p->suiv=NULL;
            return p;
            }
free(p);
}
 
//afficher un tableau
void afficher_tab(int t[])
{int i;
     for(i=0;i<9;i++)
     {
      if((i%3)==0)** { printf("\n[ %d ]",t[i]);}
 
             else {printf("[ %d ]",t[i]);}
             }
     }
 
 
//permuatation de deux entiers
void permutaion(int* a,int* b)
{int* t;
t=a;
a=b;
b=t;
}
 
//recherche d'un indice dun entier dans un tableau
int rech_ind_ent(int t[9],int x)
    {int ind = 10;
    int i=0;
        for (i=0;i<9;i++){
            if (t[i]==x) ind=i;
        }
        return ind;
 
    }
 
 
liste Test_permut(int g)
    {
    liste pp=NULL;
 
 
    switch (g)
    {
    case 0:
    {
        enfiler_l_int(&pp,1);
        enfiler_l_int(&pp,3);
    break;}
 
    case 1:
    {
        enfiler_l_int(&pp,0);
        enfiler_l_int(&pp,2);
        enfiler_l_int(&pp,4);
    break;}
 
 
    case 2:
    {
        enfiler_l_int(&pp,1);
        enfiler_l_int(&pp,5);
    break;}
 
    case 3:
    {
        enfiler_l_int(&pp,0);
        enfiler_l_int(&pp,4);
        enfiler_l_int(&pp,6);
 
    break;}
 
    case 4:
    {
        enfiler_l_int(&pp,1);
        enfiler_l_int(&pp,3);
        enfiler_l_int(&pp,5);
        enfiler_l_int(&pp,7);
 
    break;}
 
    case 5:
    {
        enfiler_l_int(&pp,2);
        enfiler_l_int(&pp,4);
        enfiler_l_int(&pp,8);
 
    break;
    }
 
    case 6:
    {
    enfiler_l_int(&pp,3);
    enfiler_l_int(&pp,7);
    break;}
 
    case 7:
    {
    enfiler_l_int(&pp,4);
    enfiler_l_int(&pp,6);
    enfiler_l_int(&pp,8);
 
    break;}
 
    case 8:
    {
    enfiler_l_int(&pp,5);
    enfiler_l_int(&pp,7);
    break;}
    default:{};
    }
 
        return pp;
    }
 
 
/******************************************************************************/
 
//structure frontiere
struct noeudf {
  int grille[9];
  int niv;
  struct noeudf *suiv;
};
typedef struct noeudf* frontiere;
 
 
frontiere creation_nf(int vval[])
{*** frontiere e = NULL ;
    e = malloc(sizeof(struct noeudf));
    e->suiv=NULL;
    if(e!=NULL) {
        int i;
    for(i=0;i<9;i++){e->grille[i] = vval[i] ;}
 
    }
    return e ;
}
 
 
/*xxxxxxxxxxxx ENFILER UN NOEUDF DANS LA FRONTIERE xxxxxxxx*/
void enfiler_f_n(frontiere* l,frontiere e)
{** frontiere* q = *l ;
 
    if(q==NULL) {*l =e;}
    else {
       while(q->suiv!=NULL) {q = q->suiv ;}
        q->suiv = e ;
 
    }
}
 
 
/*xxxxxxxxxxxx DENILER UN NOEUDF DANS LA FRONTIERE xxxxxxxx*/
frontiere defiler_f_n(frontiere* l)
{
frontiere p=*l, q=p->suiv;
if(p!=NULL){
             l=q;
            p->suiv=NULL;
            return p;
            }
free(p);
}
//******************************************************
/******************************************************************************/
/*structure noeud ab*/
 
struct noeud {
  int grille[9];
  int niv;
  struct noeud *s1;
  struct noeud *s2;
  struct noeud *s3;
  struct noeud *s4;
};
typedef struct noeud* *ab;
ab creation_ab(int vval[])
{*** ab e = NULL ;
    e = malloc(sizeof(struct noeud));
    e->s1=NULL;
    e->s2=NULL;
    e->s3=NULL;
    e->s4=NULL;
    if(e!=NULL) {
        int i;
    for(i=0;i<9;i++){e->grille[i] = vval[i] ;}
 
    }
    return e ;
}
 
 
/*xxxxxxxxxxxx ENFILER UN noeud DANS LA ab xxxxxxxx*/
void enfiler_n_ab(ab* l,ab e)
{** ab* q = *l ;
 
    if(q==NULL) {*l =e;}
    else {
       while(q->s1!=NULL) {q = q->s1 ;}
        q->s1 = e ;
 
    }
}
 
 
/*xxxxxxxxxxxx DENILER UN noeud DANS LA ab xxxxxxxx*/
ab defiler_n_ab(ab* l)
{
ab p=*l, q=p->s1;
if(p!=NULL){
             l=q;
            p->s1=NULL;
            return p;
            }
free(p);
}
/*vide ab */
int vide_l_n(ab l)
{
 
    return(l==NULL) ;
 
}
 
//XXXXXXXXXXXXXXXXXXXXXXsuccesseurXXXXXXXXXXXXXXXXXXXXXXXXXX
void successeur(ab* r)
{
    ab q=*r;
 if(q!=NULL)
 {
 
 liste pp=Test_permut(q->grille[rech_ind_ent(q->grille,0)]);
 if(pp!=NULL)
 {
     liste ds1=defiler_l_int(&pp);
     if(ds1!=NULL)
     {q->s1=creation_ab(q->grille);
     q->s1->niv=q->niv+1;
     q->s1->grille[rech_ind_ent(q->s1->grille,0)]=q->s1->grille[ds1->val];
     q->s1->grille[ds1->val]=0;
         }
         liste ds2=defiler_l_int(&pp);
     if(ds2!=NULL)
     {q->s2=creation_ab(q->grille);
     q->s2->niv=q->niv+1;
     q->s2->grille[rech_ind_ent(q->s2->grille,0)]=q->s2->grille[ds2->val];
     q->s2->grille[ds2->val]=0;
         }
/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/
     liste ds3=defiler_l_int(&pp);
     if(ds3!=NULL)
     {q->s3=creation_ab(q->grille);
     q->s3->niv=q->niv+1;
     q->s3->grille[rech_ind_ent(q->s3->grille,0)]=q->s3->grille[ds3->val];
     q->s3->grille[ds3->val]=0;
         }
 
 
 
 
    }
 
}
 
     }
 
//Parcour en largeur
void largeur(ab r)
{
     }
 
//******************************************
/*PROGRAMME PRINCIPAL*/
main()
{
int start[] = {1,2,3,4,0,5,7,8,6};
int goal[] = {1,2,3,4,5,6,7,8,0};
ab f = {NULL};
 
 
 
 
ab n1=creation_ab(start);
n1->niv=0;
liste l=Test_permut(rech_ind_ent(n1->grille,0));
 
while(l!=NULL){printf("%d>",defiler_l_int(&l)->val);}
successeur(&n1);
 
 
 
printf("\n**** RACINE *** ");
printf("\n((%d))",n1->niv);
afficher_tab(n1->grille);
printf("\n *** S1 ***");
printf("\n((%d))",n1->s1->niv);
afficher_tab(n1->s1->grille);
 
printf("\n *** S2 ***");
printf("\n((%d))",n1->s2->niv);
afficher_tab(n1->s2->grille);
 
printf("\n *** S3 ***");
printf("\n((%d))",n1->s3->niv);
afficher_tab(n1->s3->grille);
getch();
}
mais j'ai pas compris pourquoi le 3eme successeurs n'est pas créer correctement ?