#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int ind_sommet;
void ** t;
int max;
} pile;
void initPile
(pile
* p,
int _max
)
{
p
->max
= _max;
p
->t
= (void**)calloc
(_max,
sizeof(void*));
p
->ind_sommet
= 0;
}
int isPleine
(const pile
* p
)
{
return p
->max <
= p
->ind_sommet;
}
int isVide
(const pile
* p
)
{
return p
->ind_sommet<
=0;
}
int empiler
(pile
* p,
void * elem
)
{
if( !isPleine
(p
) )
{
p
->t
[p
->ind_sommet
++] = elem;
return 0;
}
return -1;
/* Pile pleine */
}
void * depiler
(pile
* p
)
{
if( !isVide
(p
) )
return p
->t
[--(p
->ind_sommet
)];
return 0;
}
int main
()
{
pile p;
int premierElement
= 12;
char deuxiemeElement
= 'T';
double troisiemeElement
= 42.
f;
short quatriemeElement
= 2;
double receptionElement1;
char receptionElement2;
int receptionElement3;
void * test;
initPile
(&p,
3);
if( empiler
(&p,
(void *) &premierElement
)!= -1 )
{
printf("Empilement Ok\n");
}
else
printf("Empilement Erreur\n");
if( empiler
(&p,
(void *) &deuxiemeElement
)!= -1 )
{
printf("Empilement Ok\n");
}
else
printf("Empilement Erreur\n");
if( empiler
(&p,
(void *) &troisiemeElement
)!= -1 )
{
printf("Empilement Ok\n");
}
else
printf("Empilement Erreur\n");
if( empiler
(&p,
(void *) &quatriemeElement
)!= -1 )
{
printf("Empilement Ok\n");
}
else
printf("Empilement Erreur\n");
receptionElement1
= *(double*)depiler
(&p
);
printf("TEST1\n");
receptionElement2
= *(char*)depiler
(&p
);
printf("TEST2\n");
receptionElement3
= *(int*)depiler
(&p
);
printf("TEST3\n");
printf("Voici les données transmises : %f, %c, %d", receptionElement1, receptionElement2, receptionElement3
);
return EXIT_SUCCESS;
}