efrei/algorithmique/piles-files/file.c

61 lines
939 B
C
Raw Normal View History

2021-09-06 16:06:52 +02:00
#include <stdio.h>
#include <stdlib.h>
2021-09-07 13:43:20 +02:00
struct maillon {
int val;
struct maillon *adr;
2021-09-06 16:06:52 +02:00
};
2021-09-07 13:43:20 +02:00
typedef struct {
struct maillon *tete, *queue;
} File;
2021-09-06 16:06:52 +02:00
2021-09-07 13:43:20 +02:00
void CreerFile(File *pf) {
pf->tete = NULL;
pf->queue = NULL;
2021-09-06 16:06:52 +02:00
}
2021-09-07 13:43:20 +02:00
int FileVide(File f) {
return (f.tete == 0);
}
2021-09-06 16:06:52 +02:00
2021-09-07 13:43:20 +02:00
int FilePleine(File f) {
return 0; // jamais pleine
2021-09-06 16:06:52 +02:00
}
2021-09-07 13:43:20 +02:00
int Enfiler(int x, File *pf) {
struct maillon *p;
if (FilePleine(*pf)) return 1;
2021-09-06 16:06:52 +02:00
2021-09-07 13:43:20 +02:00
p = malloc(sizeof(*p));
if (p == 0) return 1;
2021-09-06 16:06:52 +02:00
2021-09-07 13:43:20 +02:00
p->val = x; p->adr = 0;
if (pf->queue) pf->queue->adr = p;
else pf->tete = p;
pf->queue = p;
2021-09-06 16:06:52 +02:00
2021-09-07 13:43:20 +02:00
return 0;
2021-09-06 16:06:52 +02:00
}
2021-09-07 13:43:20 +02:00
int main() {
File f;
CreerFile(&f);
if (FileVide(f) == 1)
printf("La file est vide.\n");
else
printf("La file n'est pas vide.\n");
2021-09-06 16:06:52 +02:00
2021-09-07 13:43:20 +02:00
Enfiler(4, &f);
if (FileVide(f) == 1)
printf("La file est vide.\n");
else
printf("La file n'est pas vide.\n");
return 0;
2021-09-06 16:06:52 +02:00
}