
#include <stdio.h>
#include <stdlib.h>
#include "file.h"
void init (fifo *file)
{
    file->deb = NULL;
    file->fin = NULL;
    file->tai = 0;
}

int testL (fifo *file)
{
    if (file != NULL) return 0; // la liste n'est pas vide
    else return 1; // la liste est vide
}

void afficherL (fifo *file)
{
    cell *boite =(cell*)malloc(sizeof(cell));
    int i;
    if (testL(file) == 1)
    {
        printf("la file est vide\n");
    }
    else
    {
        boite = file->deb;
        for (i = 0; i < file->tai; i++)
        {
            printf ("%d \t", boite->val);
            boite = boite->next;
        }
    }
}

int pop (fifo *file)
{
    if (file->deb == file->fin)
    {
        cell *boite = file->deb;
        file->deb = file->fin = NULL;
        free(boite);
        file->tai--;
        return 0;
    }
    else
    {
        cell*boite = file->deb;
        file->deb = file->deb->next;
        free (boite);
        file->tai--;
        return 0;
    }
    return 1;
}

int taille (fifo *file)
{
    file->tai = file->tai + 1;
    return file->tai;
}
int push (fifo *liste, int donnee)
{
    int n;
    cell *boite = (cell*)malloc(sizeof(cell));
    boite->val = donnee;
    boite->next=NULL;
    if (liste->deb==NULL)
    {//file vide
        boite->next = liste->fin;
        liste->deb = liste->fin= boite;
        taille (liste);
        return 0;
    }
    else
    {
       /* for (n = 0; n < liste->tai; n++)
        {
            tmp = tmp->next;
        }*/
        liste->fin->next = boite;
        liste->fin=boite;

        taille(liste);
        return 0;
    }
    return 1;
}
