Advertisement
ProToTN

Untitled

May 16th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "header.h"
  4.  
  5. void display(LDC DC)
  6. {
  7.     Cellule *temp = DC.first;
  8.     while(temp != NULL)
  9.     {
  10.         printf("\nNum: %d | Surface: %.0f", temp->value.num, temp->value.surface);
  11.         temp = temp->next;
  12.     }
  13. }
  14.  
  15.  
  16. pierre getCel(pierre P, int e, int *c)
  17. {
  18.     P.forme = e;
  19.     P.surface = 100;
  20.     P.num = *c;
  21.     printf("\nOne stone added\n");
  22.     return P;
  23. }
  24.  
  25.  
  26. void stageOne(LDC *DC, int *c)
  27. {
  28.     int choix = 0;
  29.     do
  30.     {
  31.         Cellule *nouv = malloc(sizeof(Cellule));
  32.         pierre P;
  33.         nouv->value = getCel(P, 1, c);
  34.         if((DC->first == NULL)&(DC->last == NULL))
  35.         {
  36.             nouv->next = NULL;
  37.             nouv->prev = NULL;
  38.             DC->first = nouv;
  39.             DC->last = nouv;
  40.         }
  41.         else if((DC->first != NULL))
  42.         {
  43.             nouv->next = NULL;
  44.             nouv->prev = DC->last;
  45.             DC->last->next = nouv;
  46.             DC->last = nouv;
  47.         }
  48.         (*c)++;
  49.         display(*DC);
  50.         printf("\nT7eb tzid stone sa7bi? (1/0)");
  51.         scanf("%d",&choix);
  52.     }while(choix != 0);
  53. }
  54.  
  55.  
  56. void stageTwo(LDC *DC, int *c)
  57. {
  58.     Cellule *temp = DC->first;
  59.     Cellule *tempAhead;
  60.     pierre P;
  61.     int e;
  62.     printf("\nForme a ajouter (2, 3, 4, 5): \n");
  63.     scanf("%d",&e);
  64.     int i = 1;
  65.     while(temp != NULL)
  66.     {
  67.         Cellule *nouv = malloc(sizeof(Cellule));
  68.         if(temp->value.forme == 1)
  69.         {
  70.             if(temp->next == NULL)
  71.             {
  72.                 nouv->value = getCel(P, e, c);
  73.                 nouv->prev = temp;
  74.                 nouv->next = NULL;
  75.                 temp->next = nouv;
  76.                 DC->last = nouv;
  77.                 (*c)++;
  78.  
  79.             }
  80.             else
  81.             {
  82.                 nouv->value = getCel(P, e, c);
  83.                 nouv->prev = temp;
  84.                 tempAhead = temp->next;
  85.                 nouv->next = tempAhead;
  86.                 tempAhead->prev = nouv;
  87.                 temp->next = nouv;
  88.                 temp = nouv->next;
  89.                 (*c)++;
  90.             }
  91.         }
  92.         temp = temp->next;
  93.         tempAhead = tempAhead -> next;
  94.     }
  95. }
  96.  
  97.  
  98.  
  99. void stageThree(LDC *DC)
  100. {
  101.     Cellule *temp = DC->first;
  102.  
  103.     while(temp != NULL)
  104.     {
  105.         if(temp->value.forme == 1)
  106.         {
  107.             temp->value.surface -= 20;
  108.         }
  109.         temp = temp->next;
  110.     }
  111. }
  112.  
  113.  
  114.  
  115. int main()
  116. {
  117.     int choix = 0;
  118.     LDC DC;
  119.     DC.first = NULL;
  120.     DC.last = NULL;
  121.     int c = 1;
  122.     do
  123.     {
  124.         do
  125.         {
  126.             printf("\nChoisir le stage (0 to exit): \n");
  127.             scanf("%d",&choix);
  128.         }while((choix < 0)||(choix>4));
  129.  
  130.         switch(choix)
  131.         {
  132.             case 1: stageOne(&DC, &c);
  133.             break;
  134.             case 2: stageTwo(&DC, &c);
  135.                     display(DC);
  136.             break;
  137.             case 3: stageThree(&DC);
  138.                     display(DC);
  139.             break;
  140.             /*case 4: stageFour(&DC);
  141.                     display(DC);
  142.             break;*/
  143.         }
  144.     }while(!(choix == 0));
  145.     return 0;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement