diff --git a/DEV1.1/TP15/chaine.c b/DEV1.1/TP15/chaine.c new file mode 100644 index 0000000..9924411 --- /dev/null +++ b/DEV1.1/TP15/chaine.c @@ -0,0 +1,38 @@ +#include +#include +#include "pile.h" + +int main(int argc, char const *argv[]) +{ + pile *bazar; + char input1; + char input2; + printf(">"); + scanf("%c%c",&input1,&input2); + while(input1!='q') + { + printf("input1=%c input2=%c\n", input1,input2); + if (input1=='+') + { + push(&bazar,input2); + printf("Le charactere %c a été ajouté\n", input2); + input1=' '; + } + else + { + if (input1=='-') + { + printf("Le charactere %c a été supprimé\n",pop(&bazar)); + input1=' '; + } + else + { + printf(">"); + scanf("%c%c",&input1,&input2); + fflush(stdin); + } + } + } + printf("Au revoir\n"); + return 0; +} \ No newline at end of file diff --git a/DEV1.1/TP15/pile.c b/DEV1.1/TP15/pile.c new file mode 100644 index 0000000..3783107 --- /dev/null +++ b/DEV1.1/TP15/pile.c @@ -0,0 +1,55 @@ +#include +#include + +struct pile +{ + int tete; + char ple[10]; +}; + +typedef struct pile pile; + +int empty(pile *p) +{ + if(p==NULL) + { + return 1; + } + return p->tete==0; +} + +char pop(pile **p) +{ + (*p)->tete--; + return (*p)->ple[(*p)->tete]; +} + +void push(pile **p,char v) +{ + if (*p==NULL) + { + pile *new=malloc(sizeof(pile)); + new->tete=0; + *p=new; + push(p,v); + }else + { + (*p)->ple[(*p)->tete]=v; + (*p)->tete++; + } +} + +char top(pile **p) +{ + char temp = pop(p); + push(p,temp); + return temp; +} + +void clear(pile **p) +{ + while(!empty((*p))) + { + pop(p); + } +} diff --git a/DEV1.1/TP15/pile.h b/DEV1.1/TP15/pile.h new file mode 100644 index 0000000..63ca472 --- /dev/null +++ b/DEV1.1/TP15/pile.h @@ -0,0 +1,19 @@ +#ifndef _pile_h +#define _pile_h + +struct pile; + +typedef struct pile pile; + +int empty(pile *p); + +char pop(pile **p); + +void push(pile **p,char v); + +char top(pile **p); + +void clear(pile **p); + + +#endif \ No newline at end of file diff --git a/DEV1.1/random/TD15.c b/DEV1.1/random/TD15.c new file mode 100644 index 0000000..3d3cb84 --- /dev/null +++ b/DEV1.1/random/TD15.c @@ -0,0 +1,75 @@ +#include +#include + +struct pile +{ + int tete; + int max; + int ple[10]; +} + +typedef struct pile pîle; + +int empty(pile *p) +{ + if(*p==NULL) + { + return 1; + } + return p->tete==0 +} + +void push(pile **p,int v) +{ + if (*p==NULL) + { + pile *new=malloc(sizeof(pile)); + new->tete=0; + new->max=2; + int *tab=calloc(2,sizeof(int)); + new->ple=tab; + *p=new; + push(p,v); + }else + { + if ((*p)->tete==(*p)->max) + { + int *newtab=calloc(2*(*p)->max,sizeof(int)); + for (int i = 0; i < (*p)->max; ++i) + { + *(newtab+i)=*((*p)->ple+i); + } + int *temp=(*p)->ple; + (*p)->max=(*p)->max*=2; + (*p)->ple=newtab; + free(temp); + } + (*p)->ple[(*p)->tete]=v; + (*p)->tete++; + } +} + +int pop(pile **p) +{ + (*p)->tete--; + return (*p)->ple[(*p)->tete]; +} + +int main(int argc, char const *argv[]) +{ + pile *bordel; + + return 0; +} + +/* +exo 3: +1) +(7*3+7)/7 +21,42 + + + + + +*/ \ No newline at end of file