#include<stdio.h>
#include<stdlib.h>
struct Node{
int data;
struct Node *pointer;
};
struct Queue{
struct Node *head;
struct Node *tail;
};
struct Queue *Queue_Construct(void);
char Queue_Empty(struct Queue queue);
char Queue_Enqueue(struct Queue *pqueue,int a);
int Queue_Dequeue(struct Queue *pqueue);
void main()
{
struct Queue *pqueue=Queue_Construct();
Queue_Dequeue(pqueue);
Queue_Enqueue(pqueue,4);
Queue_Enqueue(pqueue,1);
Queue_Enqueue(pqueue,3);
Queue_Enqueue(pqueue,8);
printf("%6d",Queue_Dequeue(pqueue));
Queue_Enqueue(pqueue,10);
printf("enqueue completed\n");
while(Queue_Empty(*pqueue)!=1)
printf("%6d",Queue_Dequeue(pqueue));
}
struct Queue *Queue_Construct(void)
{
struct Queue *pqueue=(struct Queue *)malloc(sizeof(struct Queue));
struct Node *pNode=(struct Node *)malloc(sizeof(struct Node));//造节点
pqueue->head=pNode;
pqueue->tail=pNode;
return pqueue;
}
char Queue_Empty(struct Queue queue)
{
if(queue.head==queue.tail)
return 1;
else return 0;
}
char Queue_Enqueue(struct Queue *pqueue,int a)
{
struct Node *pNode=(struct Node *)malloc(sizeof(struct Node));//造节点
pNode->pointer=NULL;
pqueue->tail->data=a;
pqueue->tail->pointer=pNode;
pqueue->tail=pNode;
return 1;
}
int Queue_Dequeue(struct Queue *pqueue)
{
int temp;
struct Node *pNode=pqueue->head;
if(!Queue_Empty(*pqueue)){
temp=pNode->data;
pqueue->head=pNode->pointer;
free(pNode);
return temp;
}
else{
printf("Sorry,but the queue is empty");
}
}