Advertisement
RayanRam

De rien

May 17th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. typedef struct pile
  6. {
  7.          int val;
  8.          struct pile *suiv;
  9. }pile;
  10. int main(int argc, char *argv[])
  11. {
  12.     pile* P;
  13.     pile* L;
  14.     pile* Q;
  15.     int x;
  16.   int bar;
  17.   bar=0;
  18.   char s[25]={"Rien"};
  19.   do
  20.   {
  21.                 printf("Donnez la valeur ? \n");
  22.                 scanf("%d",&x);
  23.                 if(bar==0)
  24.                 {
  25.                           L = (pile*)malloc(sizeof(pile));
  26.                           L->val=x;
  27.                 L->suiv=NULL;
  28.                 bar=1;
  29.                 }
  30.                 else
  31.                 {    P=L;
  32.                      Q=P->suiv;
  33.                      if(L->val<x)
  34.                      {
  35.                     while(P->suiv!=NULL && Q->val<x)
  36.                     {
  37.                      P=P->suiv;
  38.                      Q=P->suiv;
  39.                      }
  40.                      Q=(pile*)malloc(sizeof(pile));
  41.                      Q->suiv=P->suiv;
  42.                      P->suiv=Q;
  43.                      Q->val=x;
  44.                      }
  45.                     else
  46.                     {Q=(pile*)malloc(sizeof(pile));
  47.                     Q->val=x;
  48.                     Q->suiv=L;
  49.                     L=Q;
  50.                          }
  51.                      }
  52.                      
  53.   printf("Continuer ? \n");
  54.   scanf("%s",s);
  55.   }while(strcmp(s,"NON")!=0);
  56.                     P=L;
  57.                     while(P!=NULL)
  58.                     {printf("%d \n",P->val);
  59.                     P=P->suiv;
  60.                     }
  61.   system("PAUSE");
  62.   return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement