salut j'aimerais passer une liste en parametre ,normalement l'execution doit afficher -1 0 1 2 3 .
si je fais un passage par valeur tout marche mais si je modifie la fonction pour avoir un passage par adresse ça ne marche pas correctement!(ça affiche -1 2 3).
voila mon 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
 
#include <stdio.h>
#include <stdlib.h>
#define type int
 
 
typedef struct cellule
{
        int  data;
        struct cellule *suiv;
        struct cellule *avt;
}cellule;
typedef cellule *liste;
 
 
int listeestvide(liste l)//testé
{
        if (l==NULL)
        {
                return 0;
        }
        else
        {
                return 1;
        }
}
int debut(liste l)
{
        return (int) l;
}
 
int fin(liste l)
{
        liste p=l;
        if (listeestvide(l)==1)
        {
                while(p->suiv!=NULL)
                {
                        p=p->suiv;
                }
                return (int)(p);
        }
        else
        return (int)(NULL);
}
 
 
void ajoutertete(liste *l,type elmt)
{
        cellule *nv;
        nv=malloc(sizeof(type));
        nv->data=elmt;
        nv->suiv=*l;
        *l=nv;
 
}
void  ajouterfin(liste *l,type elmt)
{
 
        cellule *nv;
        liste *p=l;
        nv=malloc(sizeof(type));
 
        nv->data=elmt;
        nv->suiv=NULL;
        if (listeestvide(*l)==1)
        {
                while((*p)->suiv!=NULL)
                {
                        *p=(*p)->suiv;
                        puts("here");
 
                }
                (*p)->suiv=nv;
 
                }
        else
        {
                *l=nv;
                puts("here");
        }
}
 
 
void affichertout(liste l)
{
        liste p=l;
        int i=1;
        while(p!=NULL)
        {
 
                printf("noeud %d:%d\n",i,p->data);
        p=p->suiv;
        i++;
        }
}
int main(void)
{
        liste l=NULL;   
        ajoutertete(&l,0);
        ajouterfin(&l,1);
        ajouterfin(&l,2);
        ajouterfin(&l,3);
        ajoutertete(&l,-1);
        affichertout(l);
return 0;
}
merci