Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct ffile ffile;
- struct ffile
- {
- int data;
- ffile* next;
- };
- ffile* creer()
- {
- return NULL;
- }
- int vide(ffile *f)
- {
- if(f)
- return 0;//correspond a non vide
- else
- return 1;//correspond a vide
- }
- void enfiler(ffile **f,int x)
- {
- ffile* p;
- p=(ffile*)malloc(sizeof(ffile));
- p->data=x;
- p->next=*f;
- *f=p;
- }
- int defiler(ffile **f)
- {
- if(!*f)
- {
- printf("Liste vide \n");
- return -999;//-999 correspond a erreur.
- }
- else if(!(*f)->next)
- {
- int x=(*f)->data;
- free (*f);
- *f=NULL;
- return x;
- }
- else
- {
- ffile *c=*f;
- while(c->next->next)
- c=c->next;
- int x;
- x=c->next->data;
- free(c->next);
- c->next=NULL;
- return x;
- }
- }
- int affiche(ffile *f)
- {
- int i=0;
- while(f){
- printf("l'element %d : %d \n",i+1,f->data);
- i++;
- f=f->next;
- }
- return i;
- }
- void liberer(ffile **f)
- {
- ffile* c=*f;
- while(*f)
- {
- *f=(*f)->next;
- free(c);
- c=(*f);
- }
- }
- void create(ffile** t)
- {
- int i;
- for(i=0;i<4;i++){
- t[i]=NULL;
- }
- }
- void ajout(ffile **t,int n)
- {
- int i;
- printf("Donner la prioritee.\n");
- do{
- scanf("%d",&i);
- }while((i>4)||(i<1));
- enfiler(&t[i-1],n);
- }
- int deff(ffile **t)
- {
- if(t[0])
- return defiler(&t[0]);
- else if(t[1])
- return defiler(&t[1]);
- else if(t[2])
- return defiler(&t[2]);
- else if(t[3])
- return defiler(&t[3]);
- else{
- printf("Erreur\n");
- return -999;//correspond a erreur.
- }
- }
- vider_stream()
- {
- char c;
- while ((c = getchar()) != '\n' && c != EOF);
- }
- int main()//file a 4 priorite.
- {
- ffile* f;
- ffile** t;
- t=malloc(4*sizeof(ffile*));
- create(t);
- ajout(t,1);
- int x=affiche(t[0]);
- printf("%d\n",x);
- x=deff(t);
- printf("%d\n",x);
- printf("%p\n",t[0]);
- return 0;
- }
- /*f=creer();
- int x;
- char c='a';
- while(c!='Q'){
- printf("Donner la commande\n");
- vider_stream();
- scanf("%c",&c);
- printf("Donner l'element a enfiler.\n");
- scanf("%d",&x);
- enfiler(&f,x);
- }
- int com;
- com=affiche(f);
- printf("Le nombre des elements est %d\n",com);
- liberer(&f);
- printf("%p\n",f);*/
Advertisement
Add Comment
Please, Sign In to add comment