Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "header.h"
- void display(LDC DC)
- {
- Cellule *temp = DC.first;
- while(temp != NULL)
- {
- printf("\nNum: %d | Surface: %.0f", temp->value.num, temp->value.surface);
- temp = temp->next;
- }
- }
- pierre getCel(pierre P, int e, int *c)
- {
- P.forme = e;
- P.surface = 100;
- P.num = *c;
- printf("\nOne stone added\n");
- return P;
- }
- void stageOne(LDC *DC, int *c)
- {
- int choix = 0;
- do
- {
- Cellule *nouv = malloc(sizeof(Cellule));
- pierre P;
- nouv->value = getCel(P, 1, c);
- if((DC->first == NULL)&(DC->last == NULL))
- {
- nouv->next = NULL;
- nouv->prev = NULL;
- DC->first = nouv;
- DC->last = nouv;
- }
- else if((DC->first != NULL))
- {
- nouv->next = NULL;
- nouv->prev = DC->last;
- DC->last->next = nouv;
- DC->last = nouv;
- }
- (*c)++;
- display(*DC);
- printf("\nT7eb tzid stone sa7bi? (1/0)");
- scanf("%d",&choix);
- }while(choix != 0);
- }
- void stageTwo(LDC *DC, int *c)
- {
- Cellule *temp = DC->first;
- Cellule *tempAhead;
- pierre P;
- int e;
- printf("\nForme a ajouter (2, 3, 4, 5): \n");
- scanf("%d",&e);
- int i = 1;
- while(temp != NULL)
- {
- Cellule *nouv = malloc(sizeof(Cellule));
- if(temp->value.forme == 1)
- {
- if(temp->next == NULL)
- {
- nouv->value = getCel(P, e, c);
- nouv->prev = temp;
- nouv->next = NULL;
- temp->next = nouv;
- DC->last = nouv;
- (*c)++;
- }
- else
- {
- nouv->value = getCel(P, e, c);
- nouv->prev = temp;
- tempAhead = temp->next;
- nouv->next = tempAhead;
- tempAhead->prev = nouv;
- temp->next = nouv;
- temp = nouv->next;
- (*c)++;
- }
- }
- temp = temp->next;
- tempAhead = tempAhead -> next;
- }
- }
- void stageThree(LDC *DC)
- {
- Cellule *temp = DC->first;
- while(temp != NULL)
- {
- if(temp->value.forme == 1)
- {
- temp->value.surface -= 20;
- }
- temp = temp->next;
- }
- }
- int main()
- {
- int choix = 0;
- LDC DC;
- DC.first = NULL;
- DC.last = NULL;
- int c = 1;
- do
- {
- do
- {
- printf("\nChoisir le stage (0 to exit): \n");
- scanf("%d",&choix);
- }while((choix < 0)||(choix>4));
- switch(choix)
- {
- case 1: stageOne(&DC, &c);
- break;
- case 2: stageTwo(&DC, &c);
- display(DC);
- break;
- case 3: stageThree(&DC);
- display(DC);
- break;
- /*case 4: stageFour(&DC);
- display(DC);
- break;*/
- }
- }while(!(choix == 0));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement