1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| #include <stdio.h>
#include <stdlib.h>
typedef struct client client ;
struct client
{
int Id,dateArrive,trait;
client*nxt;
};
typedef struct file file;
struct file
{
client*premier;
};
file *initialiser()
{
file *f =(file*) malloc(sizeof(file));
f->premier = NULL;
return f;
}
void enfiler (file *file ,int d,int at,int ar)
{
client *nouveau=(client*) malloc (sizeof(client));
if (file == NULL || nouveau== NULL)
{exit (EXIT_FAILURE);}
nouveau->Id =d;
nouveau->dateArrive =at;
nouveau->trait =ar;
nouveau->nxt=NULL;
if(file->premier != NULL)
{
client*actu=file->premier;
while (actu->nxt != NULL)
{
actu=actu->nxt;
}
actu->nxt=nouveau;
}
else {file->premier=nouveau;}
}
client* defiler (file*file)
{
if (file == NULL)
{ exit (EXIT_FAILURE);}
if (file->premier != NULL)
{
client*elemdefile=file->premier;
client*tmp=file->premier;
tmp->Id= elemdefile->Id;
tmp->dateArrive= elemdefile->dateArrive;
tmp->trait= elemdefile->trait;
file->premier = elemdefile->nxt;
free(elemdefile);
return tmp;
}
}
void afficherFile(file *file)
{
if (file=NULL)
{exit (EXIT_FAILURE);}
file *actue = file->premier;
while (actue!= NULL)
{
printf("%d",actue->Id);
printf("%d",actue->dateArrive);
printf("%d",actue->trait);
actue=actue->nxt;
}
printf ("\n");
}
int main(int argc, char *argv[])
{
file *maFile = initialiser();
enfiler (maFile,3,2,1);
enfiler (maFile,14,0,10);
enfiler (maFile,33,22,9);
afficherFile (maFile);
return 0;
} |