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 92 93 94 95 96 97 98
|
#include<stdio.h>
#include<stdlib.h>
typedef struct elmt
{
int e;
struct elmt *next;
}file;
//PROTOTYPES
file *emfiler(file *f,int a);
file *defiler(file *f);
void afficher(file *f);
file *kiem(file *f,int k);
//AJOUTER UN ELEMENT EN TETE (FIFO)
file *emfiler(file *f,int a)
{
file *tmp;
tmp=malloc(sizeof(file));
tmp->e=a;
tmp->next=f;
return tmp;
}
file *kiem(file *f,int k)
{
file *tmp;
tmp=f;
if
(k==1)
return tmp;
else
return (kiem(tmp,k-1)->next);
}
int longueur(file *f)
{
file *tmp;
tmp=f;
if(tmp==NULL)
return 0;
else
return (longueur(tmp->next)+1);
}
//SUPPRIMER UN ELEMENT DE LA QUEUE (FIFO)
file *defiler(file *f)
{
kiem(f,longueur(f)-1)->next=NULL;
return f;
}
void afficher(file *f)
{
file *tmp;
tmp=f;
printf("\n\n");
if(tmp==NULL)
printf("AUCUN ELEMENT DANS LA LISTE\n");
else
{
while(tmp!=NULL)
{
printf("\n%d",tmp->e);
tmp=tmp->next;
}
}
}
main()
{
file *f=NULL;
f=emfiler(f,10);
f=emfiler(f,20);
f=emfiler(f,30);
//f=defiler(f);
afficher(f);
printf("\n");
system("pause");
} |
Partager