typedef struct ElementListe{
int donnee;
struct ElementListe *suivant;
} Element;
typedef struct ListeRepere{
Element *debut;
int taille;
} Pile;
/* initialisation */
void initialisation (Pile *tas);
/* EMPILER*/
int empiler (Pile *tas, int *donnee);
/* DEPILER*/
int depiler (Pile *tas);
/* Affichage de élément en haut de la pile (LastInFirstOut) */
#define pile_donnee(tas) tas->debut->donnee
/* Affiche la pile */
void affiche (Pile *tas);
void initialisation (Pile * tas){
tas->debut = NULL;
tas->taille = 0;
}
/* empiler (ajouter) un élément dans la pile */
int empiler (Pile * tas, int *donnee){
Element *nouveau_element;
if ((nouveau_element = (Element *) malloc (sizeof (Element))) == NULL)
return -1;
/*if ((nouveau_element->donnee = (int *) malloc (50 * sizeof (int)))
== NULL)
return -1;*/
nouveau_element->donnee = donnee;
nouveau_element->suivant = tas->debut;
tas->debut = nouveau_element;
tas->taille++;
}
/* depiler (supprimer un élément de la pile */
int depiler (Pile * tas){
Element *supp_element;
if (tas->taille == 0)
return -1;
supp_element = tas->debut;
tas->debut = tas->debut->suivant;
free (supp_element->donnee);
free (supp_element);
tas->taille--;
return 0;
}
/* affichage de la pile */
void affiche (Pile * tas){
Element *courant;
int i;
courant = tas->debut;
for(i=0;i<tas->taille;++i){
printf("%d\n", courant->donnee);
courant = courant->suivant;
}
}
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
pile_fonction.c: In function ‘empiler’:
pile_fonction.c:18:27: warning: assignment makes integer from pointer without a cast [enabled by default]
pile_fonction.c: In function ‘depiler’:
pile_fonction.c:32:3: warning: passing argument 1 of ‘free’ makes pointer from integer without a cast [enabled by default]
/usr/include/stdlib.h:488:13: note: expected ‘void *’ but argument is of type ‘int’
pile_fonction.c: In function ‘affiche’:
pile_fonction.c:46:5: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
pile_fonction.c:46:5: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
pile_fonction.c: In function ‘empiler’:
pile_fonction.c:22:1: warning: control reaches end of non-void function [-Wreturn-type]
pile.c: In function ‘main’:
pile.c:49:3: warning: implicit declaration of function ‘set’ [-Wimplicit-function-declaration]
pile.c:50:3: warning: implicit declaration of function ‘jouer’ [-Wimplicit-function-declaration]
pile.c: At top level:
pile.c:55:6: warning: conflicting types for ‘set’ [enabled by default]
pile.c:49:3: note: previous implicit declaration of ‘set’ was here
pile.c: In function ‘set’:
pile.c:62:5: warning: passing argument 2 of ‘empiler’ makes pointer from integer without a cast [enabled by default]
pile.h:19:5: note: expected ‘int *’ but argument is of type ‘int’
pile.c: In function ‘afficher’:
pile.c:81:3: warning: statement with no effect [-Wunused-value]
pile.c:87:5: warning: statement with no effect [-Wunused-value]
pile.c:102:3: warning: statement with no effect [-Wunused-value]
pile.c:108:5: warning: statement with no effect [-Wunused-value]
pile.c:122:3: warning: statement with no effect [-Wunused-value]
pile.c:128:5: warning: statement with no effect [-Wunused-value]
pile.c:141:3: warning: statement with no effect [-Wunused-value]
pile.c: In function ‘deplacer’:
pile.c:392:3: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
pile.c:424:9: warning: passing argument 2 of ‘empiler’ makes pointer from integer without a cast [enabled by default]
pile.h:19:5: note: expected ‘int *’ but argument is of type ‘int’
pile.c:429:9: warning: passing argument 2 of ‘empiler’ makes pointer from integer without a cast [enabled by default]
pile.h:19:5: note: expected ‘int *’ but argument is of type ‘int’
pile.c:435:9: warning: passing argument 2 of ‘empiler’ makes pointer from integer without a cast [enabled by default]
pile.h:19:5: note: expected ‘int *’ but argument is of type ‘int’
pile.c:466:7: warning: passing argument 2 of ‘empiler’ makes pointer from integer without a cast [enabled by default]
pile.h:19:5: note: expected ‘int *’ but argument is of type ‘int’
pile.c:471:7: warning: passing argument 2 of ‘empiler’ makes pointer from integer without a cast [enabled by default]
pile.h:19:5: note: expected ‘int *’ but argument is of type ‘int’
pile.c:477:7: warning: passing argument 2 of ‘empiler’ makes pointer from integer without a cast [enabled by default]
pile.h:19:5: note: expected ‘int *’ but argument is of type ‘int’
pile.c:241:8: warning: variable ‘tampon’ set but not used [-Wunused-but-set-variable]
pile.c: In function ‘main’:
pile.c:52:1: warning: control reaches end of non-void function [-Wreturn-type]
/tmp/cckAhm61.o:pile.c:function main: error: undefined reference to 'jouer'
collect2: ld returned 1 exit status
Améliorer votre expérience CodeS-SourceS avec ce plugin:
ttp://codes-sources.commentcamarche.net/forum/affich-10000111-plugin-better-cs-2#cptpingu-signature