Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct coda{
- int inf;
- struct coda *pun;
- };
- /*funzioni*/
- int menuCoda();
- struct coda *creaCoda(int *);
- void enqueueCoda(struct coda *, int *);
- struct coda *dequeueCoda(struct coda *);
- struct coda *clearCoda(struct coda *);
- void printCoda(struct coda *);
- main()
- {
- struct coda *puntTesta=NULL;
- int menu=-1, numerino;
- while(menu!=0){
- if(menu==-1) menu=1;
- else { printCoda(puntTesta); menu=menuCoda();}
- switch(menu){
- case 1: {
- system("cls");
- if(puntTesta==NULL) puntTesta= creaCoda(&numerino);
- else enqueueCoda(puntTesta, &numerino); break;}
- case 2: {
- puntTesta= dequeueCoda(puntTesta); break;}
- case 3: {puntTesta= clearCoda(puntTesta); break;}
- case 4: {printCoda(puntTesta); printf("\n\n\nIn attesa..."); getchar(); break;}
- case 5: {menu=0; break;}
- default:{
- printf("opzione non ammessa");
- printf("\n\n\nIn attesa...\t");
- getchar();}
- }
- system("cls"); }
- return 0;
- }
- /*menu'*/
- int menuCoda()
- {
- int menu;
- printf("\n\n------------- MENU'------------\n");
- printf("\n1. Prendi numerino\n\n2. Avanti il prossimo\n\n3. Svuota pila\n\n5. Exit\n\n ");
- scanf("%d", &menu);
- getchar();
- return menu;
- }
- /*crea lista*/
- struct coda *creaCoda(int *num)
- {
- struct coda *p;
- p=(struct coda *)malloc(sizeof(struct coda));
- printf("\nIl suo numero e': 1\t");
- getchar();
- *num=1;
- p->inf=1;
- p->pun=NULL;
- return(p);
- }
- void enqueueCoda(struct coda *p, int *num)
- {
- system("cls");
- printCoda(p);
- struct coda *paus=p;
- while(p!=NULL){
- paus=p;
- p=p->pun;}
- ++*num; if(*num==100) *num=1;
- printf("\n\nIl suo numero e': %d\t", *num);
- getchar();
- paus->pun=(struct coda *)malloc(sizeof(struct coda));
- paus=paus->pun;
- paus->inf=*num; paus->pun=NULL;
- }
- struct coda *dequeueCoda(struct coda *p)
- {
- struct coda *paus=p;
- system("cls");
- printCoda(p);
- p=p->pun;
- printf("\n\n\tServiamo il: %d", paus->inf);
- printf("\n\nIn attesa...");
- getchar();
- free(paus);
- return p;
- }
- struct coda *clearCoda(struct coda *p)
- {
- struct coda *paus;
- system("cls");
- while(p!=NULL){
- paus=p;
- p=p->pun;
- free(paus);}
- printf("\n\n\n\n\t\tCoda svuotata!!\n\n\n\n");
- getchar();
- return NULL;
- }
- void printCoda(struct coda *p)
- {
- int numPers=0;
- system("cls");
- printf("\n\t\t-------------------> Il prossimo");
- printf("\n\t|\t \t|");
- while(p!=NULL){
- printf("\n\t|\t%d\t|", p->inf);
- numPers++;
- p=p->pun;}
- printf("\n\t|\t \t|");
- printf("\n\t\t<------------------- Ultimo arrivato\n\nPersone in coda: %d\t", numPers);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement