mittimus

File CODA.C

Jul 17th, 2012
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include<stdlib.h>
  2. #define CODAVUOTA NULL
  3. typedef short boolean;
  4. struct nodoQueue {
  5. tipobaseQueue info;
  6. struct nodoQueue *next;
  7. };
  8. typedef struct {
  9. struct nodoQueue * front, * rear;
  10. } queue;
  11. void MakeNullQueue(queue *q)
  12. {
  13. q->front=q->rear=CODAVUOTA;
  14. }
  15. boolean EmptyQueue(queue q)
  16. {
  17. return(q.front==CODAVUOTA);
  18. }
  19. boolean FullQueue(queue q)
  20. {
  21. return(0);
  22. }
  23. void EnQueue(queue *q, tipobaseQueue x)
  24. {
  25. struct nodoQueue * temp;
  26. if (!FullQueue(*q)) {
  27. temp=(struct nodoQueue *)malloc(sizeof(struct nodoQueue));
  28. temp->info=x;
  29. temp->next=CODAVUOTA;
  30. if (EmptyQueue(*q)) q->front=q->rear=temp;
  31. else {
  32. q->rear->next=temp;
  33. q->rear=temp;
  34. }
  35. }
  36. }
  37. void DeQueue(queue *q)
  38. {
  39. struct nodoQueue * temp;
  40. if (!EmptyQueue(*q)) {
  41. temp=q->front->next;
  42. free (q->front);
  43. q->front=temp;
  44. if (q->front==CODAVUOTA) q->rear=CODAVUOTA;
  45. }
  46. }
  47. Prof.Ing.S.Cavalieri
  48. L’ADT Coda in Linguaggio C a.a.2010/2011
  49. 15
  50. tipobaseQueue Front(queue q)
  51. {
  52. if (!EmptyQueue(q))
  53. return(q.front->info);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment