Developpement/23DEV1.1/TPS1/TP2/24-Files/Chainee.c

78 lines
1.2 KiB
C
Raw Normal View History

2024-12-09 11:53:11 +01:00
#include <stdio.h>
#include <stdlib.h>
struct maillon_s{
char valeur;
struct maillon_s* suivant;
};
typedef struct maillon_s maillon;
struct file{
maillon* premier;
maillon* dernier;
};
/*void clear(file* f){
}
char first(file* f){
}*/
void enqueue(file* f, char new){
maillon* m = (maillon) malloc(sizeof(maillon));
m->valeur = nouveaux;
m->suivant=NULL;
if(f->dernier!=NULL){
f->dernier->suivant = m;
}else{
f->permier = m;
}
f->dernier = m;
}
char dequeue(file* f){
maillon m = *(f->premier);
free(f->premier);
f->premier = m.suivant;
if(f->premier == NULL){
f->dernier = NULL;
}
return m.valeur;
}
int empty(const file* f){
return f->premier == NULL;
}
int main(void){
int n;
char ch[2];
struct file* f;
char val;
n = 0;
printf("Le File attends vos ordre\n");
while(n < 2){
ch[n] = getchar();
n++;
}
while(ch[0] != 'q'){
n = 0;
if(ch[0] == '+'){
val = ch[1];
enqueue(f, val);
printf("Le caractère %c a ete ajoute\n", val);
}else if(ch[0] == '-'){
val = dequeue(f);
printf("Le caractère %c a ete supprime\n", val);
}
printf(">");
while(n < 2){
ch[n] = getchar();
n++;
}
}
printf("Au revoir");
}