#include
#include
typedef struct Queue
{
int *pBase;
int front;
int rear;
}QUEUE, *PQUEUE ;
void init_queue(PQUEUE);//初始化队列
void full_queue(PQUEUE);//判断队列是否已满
void en_queue(PQUEUE, int);//入队
void is_empty_queue(PQUEUE);//判断队列是否为空
void traverse_queue(PQUEUE);//遍历队列
void out_queue(PQUEUE);//出队
int main(int argc, const char * argv[])
{
QUEUE q;
init_queue(&q);
en_queue(&q, 1);
en_queue(&q, 2);
en_queue(&q, 3);
en_queue(&q, 4);
en_queue(&q, 5);
//en_queue(&q, 6);
//en_queue(&q, 7);
traverse_queue(&q);
out_queue(&q);
traverse_queue(&q);
return 0;
}
//初始化队列
void init_queue(PQUEUE pQ)
{
pQ->pBase = (int *)malloc(sizeof(int)*6);
pQ->front = 0;
pQ->rear = 0;
return;
}
//判断队列是否已满
void full_queue(PQUEUE pQ)
{
if ((pQ->rear + 1) % 6 == pQ->front) {
printf("队列已满!!!\n");
exit(-1);
}
return;
}
//入队
void en_queue(PQUEUE pQ,int val)
{
full_queue(pQ);
pQ->pBase[pQ->rear] = val;
pQ->rear = (pQ->rear + 1) %6;
return;
}
//判断队列是否为空
void is_empty_queue(PQUEUE pQ)
{
if (pQ->front == pQ->rear) {
printf("队列为空!!!\n");
exit(-1);
}
return;
}
//遍历队列
void traverse_queue(PQUEUE pQ)
{
is_empty_queue(pQ);
printf("遍历结果为:");
int i = pQ->front;
while (i != pQ->rear) {
printf("%d ",pQ->pBase[i]);
i = (i+1) % 6;
}
printf("\n");
return;
}
//出队
void out_queue(PQUEUE pQ)
{
is_empty_queue(pQ);
int val;
val = pQ->pBase[pQ->front];
pQ->front = (pQ->front+1) % 6;
printf("元素%d出对\n",val);
return;
}
#include
typedef struct Queue
{
}QUEUE, *PQUEUE ;
void init_queue(PQUEUE);//初始化队列
void full_queue(PQUEUE);//判断队列是否已满
void en_queue(PQUEUE, int);//入队
void is_empty_queue(PQUEUE);//判断队列是否为空
void traverse_queue(PQUEUE);//遍历队列
void out_queue(PQUEUE);//出队
int main(int argc, const char * argv[])
{
}
//初始化队列
void init_queue(PQUEUE pQ)
{
}
//判断队列是否已满
void full_queue(PQUEUE pQ)
{
}
//入队
void en_queue(PQUEUE pQ,int val)
{
}
//判断队列是否为空
void is_empty_queue(PQUEUE pQ)
{
}
//遍历队列
void traverse_queue(PQUEUE pQ)
{
}
//出队
void out_queue(PQUEUE pQ)
{
}