Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct noeud
- {
- int donnees;
- struct noeud *suivant;
- };
- struct noeud *pile = NULL;
- void empiler(int element)
- {
- struct noeud *nptr = malloc(sizeof(struct noeud));
- nptr->donnees = element;
- nptr->suivant = pile;
- pile = nptr;
- }
- void afficher()
- {
- struct noeud *temp;
- temp = pile;
- while (temp != NULL)
- {
- printf("\n%d", temp->donnees);
- temp = temp->suivant;
- }
- }
- void depiler()
- {
- if (pile == NULL)
- {
- printf("\n\nLa pile est vide ");
- }
- else
- {
- struct noeud *temp;
- temp = pile;
- pile = pile->suivant;
- printf("\n\n%d supprime", temp->donnees);
- free(temp);
- }
- }
- int main()
- {
- int n, ch;
- do
- {
- printf("\n\nMenu Pile\n1. Empiler \n2. Depiler\n3. Afficher\n0. Quittez");
- printf("\nEntrer votre choix 0-3 ? : ");
- scanf("%d", &ch);
- switch (ch)
- {
- case 1:
- printf("\nEntrer un nombre ");
- scanf("%d", &n);
- empiler(n);
- break;
- case 2:
- depiler();
- break;
- case 3:
- afficher();
- break;
- }
- }while (ch != 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement