#include "file.h"

file* fileVide(){
    file* f=(file*)malloc(sizeof(file));
    f->debut=NULL;
    f->fin=NULL;
    return f;

}

bool est_file_vide(file* f){
    return(f->debut ==NULL);
}

void enfiler (file* f, int x){
    liste new_noeud = (liste)malloc(sizeof(noeud));
    new_noeud->val=x;

    new_noeud->next=NULL;
    if (f->debut==NULL){
        f->debut=new_noeud;
        f->fin=new_noeud;
        
    }
    else{assert(f->fin!=NULL);
        f->fin->next=new_noeud;
        f->fin=new_noeud;
        
    }
}

void libere_noeud(noeud* n){
    if(n!=NULL){
        libere_noeud(n->next);
        free(n);
    }
}

void libere(file* f){
    if (f!=NULL){
        libere_noeud(f->debut);
    }
}

int defiler (file* f){
    assert(f->debut != NULL && f->fin !=NULL );
    int x = f->debut->val;
    noeud* n= f->debut;
    f->debut=f->debut->next;
    if(f->debut==NULL){
        f->fin=NULL;
    }
    free(n);
    return x;
    
}