diff --git a/src/annexe/saeAnnexe.c b/src/annexe/saeAnnexe.c index 17c8715..e935428 100644 --- a/src/annexe/saeAnnexe.c +++ b/src/annexe/saeAnnexe.c @@ -13,4 +13,105 @@ void menu(void){ printf("C : Consultation.\n"); printf("A : Administrateur.\n\n"); printf("#--------------------------------------------------------------------#\n"); +} + +//Pile +Pile creerpile(int tmax) +{ + Pile p=(Pile)malloc(sizeof(pile)); + p->tlogi=0; + p->tmax=tmax; + p->tab=(int*) malloc(tmax); + return p; +} + +void empiler(Pile p, int x) +{ + if (p->tmax==p->tlogi) + { + printf("Pile pleine"); + return; + } + p->tab[p->tlogi++]=x; +} + +void afficherPileEntier(Pile p) +{ + for (int i=0; itlogi;i++) printf("%d\n",p->tab[i]); +} + +int depiler(Pile p) +{ + if (p->tlogi==0) + { + printf("Pile vide"); + return -1; + } + return p->tab[--(p->tlogi)]; +} + +//File +File creerfile(int tmax) +{ + File f=(File)malloc(sizeof(file)); + Pile inipEntry=(Pile)malloc(sizeof(pile)/2); + Pile inipExit=(Pile)malloc(tmax-sizeof(pile)/2); + if (f==NULL || inipEntry==NULL || inipExit==NULL) + { + printf("Erreur maloc ini file\n"); + exit(1); + } + + inipEntry->tlogi=0; + inipEntry->tmax=tmax; + inipEntry->tab=(int*) malloc(tmax); + + inipExit->tlogi=0; + inipExit->tmax=tmax-tmax/2; + inipExit->tab=(int*) malloc(tmax); + + f->pEntry=inipEntry; + f->pExit=inipExit; + return f; +} + +void vider_file(File f) +{ + while (f->pExit->tmax!=f->pExit->tlogi && f->pEntry->tlogi!=0) + { + empiler(f->pExit,depiler(f->pEntry)); + } +} + +void enfiler(File f, int x) +{ + if (f->pEntry->tlogi==f->pEntry->tmax) + { + vider_file(f); + } + f->pEntry->tab[f->pEntry->tlogi]=x; + f->pEntry->tlogi++; +} + +int defiler(File f) +{ + if (f->pExit->tlogi==0) + { + vider_file(f); + } + + if (f->pExit->tlogi==0) + { + printf("File vide"); + return -1; + } + + f->pExit->tlogi--; + return f->pExit->tab[f->pExit->tlogi]; +} + +void afficherFileEntier(File f) +{ + for(int i=0;ipExit->tlogi;++i) printf("%d\n",f->pExit->tab[i]); + for(int i=f->pEntry->tlogi;i!=0;--i) printf("%d\n",f->pEntry->tab[i]); } \ No newline at end of file diff --git a/src/annexe/saeAnnexe.h b/src/annexe/saeAnnexe.h index 8b13789..a65671d 100644 --- a/src/annexe/saeAnnexe.h +++ b/src/annexe/saeAnnexe.h @@ -1 +1,38 @@ +//Pile +typedef struct pile +{ + int tlogi; + int tmax; + int* tab; +} pile; +typedef struct pile* Pile; + +Pile creerpile(int tmax); + +void empiler(Pile p, int x); + +void afficherPileEntier(Pile p); + +int depiler(Pile p); + + +//File +typedef struct file +{ + Pile pEntry; + Pile pExit; + int* tab; +} file; +typedef struct file* File; + + +File creerfile(int tmax); + +void enfiler(File f, int x); + +void afficherFileEntier(File f); + +int defiler(File f); + +void vider_file(File f);