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
| #include <stdio.h>
/* Ce programme effectue l'inversion d'une chaîne de caractères.*/
/* Version liste chainé */
void initialiser_pile();
int pile_est_vide();
void empile(char objet);
char depile();
int nb_element;
typedef struct{
char element;
struct PILE* suiv;
struct PILE* prec;
}PILE;
void initialiser_PILE(PILE* l);
struct PILE *pile, *fin_pile;
main(){
initialiser_pile();
char caractere = ' ';
printf("Entrer une chaine de caractere(s) : ");
while(caractere != '\n'){
scanf("%c", &caractere);
empile(caractere);
}
while(!pile_est_vide()){
printf("%c",depile());
}
}
void initialiser_PILE(PILE* l){
l->element = '\n';
l->prec = NULL;
l->suiv = NULL;
}
void initialiser_pile(){
pile = NULL;
fin_pile = NULL;
}
int pile_est_vide(){return !pile;}
void empile(char objet){
struct PILE *new_maillon;
new_maillon = (struct PILE *) malloc(sizeof(struct PILE));
initialiser_PILE(new_maillon);
new_maillon->element = objet;
if(pile == NULL){
pile = new_maillon;
fin_pile = new_maillon;
}
else{
fin_pile->suiv = new_maillon;
new_maillon->prec = fin_pile;
new_maillon->suiv = NULL;
new_maillon = fin_pile;
}
} |
Partager