Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #define CODAVUOTA NULL
- typedef short boolean;
- struct nodoQueue {
- tipobaseQueue info;
- struct nodoQueue *next;
- };
- typedef struct {
- struct nodoQueue * front, * rear;
- } queue;
- void MakeNullQueue(queue *q)
- {
- q->front=q->rear=CODAVUOTA;
- }
- boolean EmptyQueue(queue q)
- {
- return(q.front==CODAVUOTA);
- }
- boolean FullQueue(queue q)
- {
- return(0);
- }
- void EnQueue(queue *q, tipobaseQueue x)
- {
- struct nodoQueue * temp;
- if (!FullQueue(*q)) {
- temp=(struct nodoQueue *)malloc(sizeof(struct nodoQueue));
- temp->info=x;
- temp->next=CODAVUOTA;
- if (EmptyQueue(*q)) q->front=q->rear=temp;
- else {
- q->rear->next=temp;
- q->rear=temp;
- }
- }
- }
- void DeQueue(queue *q)
- {
- struct nodoQueue * temp;
- if (!EmptyQueue(*q)) {
- temp=q->front->next;
- free (q->front);
- q->front=temp;
- if (q->front==CODAVUOTA) q->rear=CODAVUOTA;
- }
- }
- Prof.Ing.S.Cavalieri
- L’ADT Coda in Linguaggio C a.a.2010/2011
- 15
- tipobaseQueue Front(queue q)
- {
- if (!EmptyQueue(q))
- return(q.front->info);
- }
Advertisement
Add Comment
Please, Sign In to add comment