From e4498c21e77c53bc0f68f7e5dd49a8ea28438947 Mon Sep 17 00:00:00 2001 From: Simon Saye Babu Date: Wed, 11 Jan 2023 14:14:52 +0100 Subject: [PATCH] pile --- DEV1.1/TP15/chaine.c | 3 +- DEV1.1/TP15/file.c | 56 +++++++++++++++++++++++++ DEV1.1/TP15/patate | 1 + DEV1.1/TP15/pile.c | 86 ++++++++++++++++++++++++++++++++++++++ DEV1.1/random/decryptage.c | 2 + DEV1.1/random/liste.c | 63 ++++++++++++++++++++++++++++ 6 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 DEV1.1/TP15/file.c create mode 100644 DEV1.1/TP15/patate create mode 100644 DEV1.1/random/decryptage.c create mode 100644 DEV1.1/random/liste.c diff --git a/DEV1.1/TP15/chaine.c b/DEV1.1/TP15/chaine.c index 9924411..d9f5116 100644 --- a/DEV1.1/TP15/chaine.c +++ b/DEV1.1/TP15/chaine.c @@ -28,8 +28,7 @@ int main(int argc, char const *argv[]) else { printf(">"); - scanf("%c%c",&input1,&input2); - fflush(stdin); + scanf("%c%c",&input1,&input2); } } } diff --git a/DEV1.1/TP15/file.c b/DEV1.1/TP15/file.c new file mode 100644 index 0000000..16da646 --- /dev/null +++ b/DEV1.1/TP15/file.c @@ -0,0 +1,56 @@ +#include +#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); + } +} \ No newline at end of file diff --git a/DEV1.1/TP15/patate b/DEV1.1/TP15/patate new file mode 100644 index 0000000..59a4820 --- /dev/null +++ b/DEV1.1/TP15/patate @@ -0,0 +1 @@ +([{{{{[[((())])]}}}}]) \ No newline at end of file diff --git a/DEV1.1/TP15/pile.c b/DEV1.1/TP15/pile.c index 3783107..030b14c 100644 --- a/DEV1.1/TP15/pile.c +++ b/DEV1.1/TP15/pile.c @@ -1,5 +1,6 @@ #include #include +#include struct pile { @@ -53,3 +54,88 @@ void clear(pile **p) pop(p); } } + +int main(int argc, char const *argv[]) +{ + FILE *f; + f=fopen(argv[1],"r"); + pile *test = malloc(sizeof(pile)); + char c; + char temp; + int verif; + fread(&c,1,1,f); + while(!feof(f)==1) + { + printf("%c\n", c); + if (c=='('||c=='['||c=='{') + { + push(&test,c); + } + else + { + if (c==')'||c==']'||c=='}') + { + verif = 0; + if (!empty(test)) + { + temp = pop(&test); + printf("c = %c et test = %c\n",c,temp); + switch(c) + { + case ')': + if (temp == '(') + { + break; + } + else + { + verif++; + } + break; + case ']': + if (temp == '[') + { + break; + } + else + { + verif++; + } + break; + case '}': + if (temp == '{') + { + break; + } + else + { + verif++; + } + break; + default: + break; + } + if (verif!=0) + { + break; + } + } + else + { + printf("Le fichier est mal parenthesé (parenthese en trop) !\n"); + return 1; + } + } + } + fread(&c,1,1,f); + } + if (verif!=0) + { + printf("Le fichier est mal parenthesé ! (parenthse au mauvaise endroit)\n"); + } + else + { + printf("Le fichier est bien parenthesé !\n"); + } + return 0; +} \ No newline at end of file diff --git a/DEV1.1/random/decryptage.c b/DEV1.1/random/decryptage.c new file mode 100644 index 0000000..d807850 --- /dev/null +++ b/DEV1.1/random/decryptage.c @@ -0,0 +1,2 @@ +#include +#include \ No newline at end of file diff --git a/DEV1.1/random/liste.c b/DEV1.1/random/liste.c new file mode 100644 index 0000000..43ebf44 --- /dev/null +++ b/DEV1.1/random/liste.c @@ -0,0 +1,63 @@ +#include +#include + +struct file +{ + int data; + struct file* succ; + struct file* last; +}; + +typedef struct file file; + +int empty(file *f) +{ + return f==NULL; +} + +void enqueue(file **f, int v) +{ + file *nouveau=malloc(sizeof(file)); + nouveau -> data = v; + nouveau -> succ = NULL; + nouveau -> last = nouveau; + if ((*f)!=NULL) + { + (*f) -> last -> succ = nouveau; + (*f) -> last = nouveau; + } + else + { + (*f)=nouveau; + } +} + +int dequeue(file **f) +{ + int resultat = (*f) -> data; + file *temp = *f; + (*f)=(*f)-> succ; + if ((*f)!=NULL) + { + (*f) -> last = temp -> last; + } + free(temp); + return resultat; +} + + +int main(int argc, char const *argv[]) +{ + file *f = NULL; + for (int i = 0; i < 15; ++i) + { + enqueue(&f,i); + } + int i=0; + while(!empty(f)) + { + printf("%s\n",dequeue(&f) ); + + } + return 0; +} \ No newline at end of file