88 lines
1.7 KiB
C
88 lines
1.7 KiB
C
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
|
|
typedef struct m{
|
|
char valeur;
|
|
struct m* suivant;
|
|
} maillon;
|
|
|
|
typedef struct file{
|
|
maillon* debut;
|
|
maillon* fin;
|
|
}file;
|
|
|
|
int empty(file p_file){
|
|
if (p_file.debut){
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void enqueue(file* p_file, char new_valeur){
|
|
maillon* new_maillon = (maillon*) malloc(sizeof(maillon));
|
|
new_maillon->valeur = new_valeur;
|
|
new_maillon->suivant = NULL;
|
|
if ((*p_file).debut==NULL){
|
|
p_file->debut = new_maillon;
|
|
}
|
|
else{
|
|
(p_file->fin)->suivant = new_maillon;
|
|
}
|
|
p_file->fin = new_maillon;
|
|
}
|
|
|
|
char dequeue(file* p_file){
|
|
maillon* p_suivant=(p_file->debut)->suivant;
|
|
char valeur = (p_file->debut)->valeur;
|
|
free(p_file->debut);
|
|
p_file->debut = p_suivant;
|
|
return valeur;
|
|
}
|
|
|
|
char old(file p_file){
|
|
return (p_file.debut)->valeur;
|
|
}
|
|
|
|
void clear(file* p_file){
|
|
maillon* p_suivant = (*p_file).debut;
|
|
while(p_suivant!=NULL){
|
|
p_suivant = ((*p_file).debut)->suivant;
|
|
free((*p_file).debut);
|
|
p_file->debut = p_suivant;
|
|
}
|
|
p_file->fin = NULL;
|
|
}
|
|
|
|
int main(void){
|
|
int choix=99;
|
|
char caractere;
|
|
file p_file;
|
|
p_file.debut=NULL;
|
|
p_file.fin=NULL;
|
|
printf("\n----------instruction----------\n1<char>- enqueue\n2- dequeue\n3- old\n4- clear\n5- quit\n----------------------------------\n");
|
|
while(choix!=5){
|
|
printf("choix : ");
|
|
scanf("%d%c",&choix,&caractere);
|
|
if (choix==1){
|
|
enqueue(&p_file,caractere);
|
|
}
|
|
if (choix==2){
|
|
if (empty(p_file)){
|
|
printf("resultat : %c\n",dequeue(&p_file));
|
|
}
|
|
}
|
|
if (choix==3){
|
|
if (empty(p_file)){
|
|
printf("resultat : %c\n",old(p_file));
|
|
}
|
|
}
|
|
if (choix==4){
|
|
clear(&p_file);
|
|
printf("La liste à bien été vidé\n");
|
|
}
|
|
}
|
|
clear(&p_file);
|
|
printf("O revoir BG\n");
|
|
return 0;
|
|
}
|