Bonjour a tous,

Moi aussi j'ai trouvé des difficultés pour transformer cette fonction « recur » en une fonction itérative. Donc veuillez m'aider à la faire :

voici la fonction :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void F3_Rec (int x, int y)
{
    Inst1 ; Inst2 ;
 
    if (x>0 && y>0)
    {
        x= x/10 ; y= y/10 ;
        F3_Rec (x,y) ;  
        Inst3 ; Inst4 ;
    }
 
    Inst5 ; Inst6 ;
    F3_Rec (x,y);
}
et voici ma réponse (chui sur qu'elle n'est pas bonne ) :

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
Void  F3_iter (int x,int y)
{
    pile *P,*S;
 
    initpile(&P);
    initpile(&S) ;
 
    Inst1; Inst2 ;
 
    While(x>0 && y>0)
    {
        x=x/10 ; y=y/10 ;
        empiler(&P,x);
        empiler(&P,y);
 
        inst1; inst2;
    }
 
    {
        inst5; inst6;
    }
 
    while (!pilevide(P))
    {
        depiler(&P,&y);
        depiler(&P,&x);
        inst3; inst4; inst5; inst6;
        empiler(&S,&x);
        empiler(&S,&y);
    }
 
    while( !pilevide(S))
    {
        depiler(&S,&y);
        depiler(&S,&x);
        inst1 ;inst2 ;
        {inst5 ;inst6 ;}
 
        while (!pilevide(S))
        {
            depiler(&S,&y);
            depiler(&S,&x);
            inst3 ;inst4 ;inst5 ;inst6 ;
        }