Advertisement
FiddleComputers

Dynamic queue essentials C

Jan 12th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct noeud
  5. {
  6.     int donnees;
  7.     struct noeud *suivant;
  8. };
  9.  
  10. struct noeud *avant = NULL;
  11. struct noeud *arriere = NULL;
  12.  
  13. void enfiler(int element)
  14. {
  15.     struct noeud *nptr = malloc(sizeof(struct noeud));
  16.     nptr->donnees = element;
  17.     nptr->suivant = NULL;
  18.     if (arriere == NULL)
  19.     {
  20.         avant = nptr;
  21.         arriere = nptr;
  22.     }
  23.     else
  24.     {
  25.         arriere->suivant = nptr;
  26.         arriere = arriere->suivant;
  27.     }
  28. }
  29.  
  30. void afficher()
  31. {
  32.     struct noeud *temp;
  33.     temp = avant;
  34.     printf("\n");
  35.     while (temp != NULL)
  36.     {
  37.         printf("%d\t", temp->donnees);
  38.         temp = temp->suivant;
  39.     }
  40. }
  41.  
  42. void defiler()
  43. {
  44.     if (avant == NULL)
  45.     {
  46.         printf("\n\nLa file est vide \n");
  47.     }
  48.     else
  49.     {
  50.         struct noeud *temp;
  51.         temp = avant;
  52.         avant = avant->suivant;
  53.         printf("\n\n%d supprime", temp->donnees);
  54.         free(temp);
  55.     }
  56. }
  57.  
  58. int main()
  59. {
  60.     int n, ch;
  61.     do
  62.     {
  63.         printf("\n\nMenu File\n1. Ajouter \n2. Retirer\n3. Afficher\n0. Quitter");
  64.         printf("\nEntrer votre choix 0-3 ? : ");
  65.         scanf("%d", &ch);
  66.         switch (ch)
  67.         {
  68.             case 1:
  69.                 printf("\nEntrer un nombre ");
  70.                 scanf("%d", &n);
  71.                 enfiler(n);
  72.                 break;
  73.             case 2:
  74.                 defiler();
  75.                 break;
  76.             case 3:
  77.                 afficher();
  78.                 break;
  79.         }
  80.     }while (ch != 0);
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement