63 lines
807 B
C
63 lines
807 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
struct file
|
|
{
|
|
int data;
|
|
struct file* succ;
|
|
struct file* last;
|
|
};
|
|
|
|
typedef struct file file;
|
|
|
|
int empty(file *f)
|
|
{
|
|
return f==NULL;
|
|
}
|
|
|
|
void enqueue(file **f, int v)
|
|
{
|
|
file *nouveau=malloc(sizeof(file));
|
|
nouveau -> data = v;
|
|
nouveau -> succ = NULL;
|
|
nouveau -> last = nouveau;
|
|
if ((*f)!=NULL)
|
|
{
|
|
(*f) -> last -> succ = nouveau;
|
|
(*f) -> last = nouveau;
|
|
}
|
|
else
|
|
{
|
|
(*f)=nouveau;
|
|
}
|
|
}
|
|
|
|
int dequeue(file **f)
|
|
{
|
|
int resultat = (*f) -> data;
|
|
file *temp = *f;
|
|
(*f)=(*f)-> succ;
|
|
if ((*f)!=NULL)
|
|
{
|
|
(*f) -> last = temp -> last;
|
|
}
|
|
free(temp);
|
|
return resultat;
|
|
}
|
|
|
|
|
|
int main(int argc, char const *argv[])
|
|
{
|
|
file *f = NULL;
|
|
for (int i = 0; i < 15; ++i)
|
|
{
|
|
enqueue(&f,i);
|
|
}
|
|
int i=0;
|
|
while(!empty(f))
|
|
{
|
|
printf("%s\n",dequeue(&f) );
|
|
|
|
}
|
|
return 0;
|
|
} |