Start file.c and pile.c

This commit is contained in:
flyingscorpio@pinebookpro 2021-09-07 13:43:20 +02:00
parent c6e77914ae
commit f1335dc1ee
3 changed files with 80 additions and 22 deletions

View file

@ -0,0 +1,10 @@
all: pile file
pile: pile.c
gcc pile.c -o pile
file: file.c
gcc file.c -o file
clean:
rm file pile

View file

@ -1,33 +1,60 @@
#include <stdio.h>
#include <stdlib.h>
struct File {
int *tête;
int *queue;
struct maillon {
int val;
struct maillon *adr;
};
int main() {
typedef struct {
struct maillon *tete, *queue;
} File;
void CreerFile(File *pf) {
pf->tete = NULL;
pf->queue = NULL;
}
int FileVide(File f) {
return (f.tete == 0);
}
int FilePleine(File f) {
return 0; // jamais pleine
}
int Enfiler(int x, File *pf) {
struct maillon *p;
if (FilePleine(*pf)) return 1;
p = malloc(sizeof(*p));
if (p == 0) return 1;
p->val = x; p->adr = 0;
if (pf->queue) pf->queue->adr = p;
else pf->tete = p;
pf->queue = p;
return 0;
}
void InitialiserFile(struct File F) {
}
int EstFileVide(struct File F) {
if (F.tête == F.queue)
return 0;
return 1;
}
void Enfiler(int x, struct File F) {
F.queue++;
&F.queue = x;
}
void Défiler(int x, struct File F) {
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");
Enfiler(4, &f);
if (FileVide(f) == 1)
printf("La file est vide.\n");
else
printf("La file n'est pas vide.\n");
return 0;
}

View file

@ -0,0 +1,21 @@
/* Implémentation d'une pile */
#include <stdio.h>
#include <stdlib.h>
struct maillon {
int val;
struct maillon *adr;
};
typedef struct maillon *Pile;
void CreerPile(Pile *p) {
*p = 0;
}
int PileVide(Pile p) {
return 1;
}
int main() {
}