#include<stdio.h>
#include<malloc.h>
typedef struct queue
{
int * base;
int front;
int rear;
}Queue,*PQueue;
PQueue init_Queue(PQueue queue);
void in_Queue(PQueue queue,int val);
void out_Queue(PQueue queue);
void traversal(PQueue queue);
int isFull(PQueue queue);
int isEmpty(PQueue queue);
int main()
{
Queue queue;
PQueue pqueue=init_Queue(&queue);
in_Queue(pqueue,1);
in_Queue(pqueue,2);
in_Queue(pqueue,3);
in_Queue(pqueue,4);
in_Queue(pqueue,5);
traversal(pqueue);
out_Queue(pqueue);
traversal(pqueue);
return 0;
}
PQueue init_Queue(PQueue queue)
{
queue->base=(int *)malloc(sizeof(int)*6);//定义一个数组
queue->front=0;
queue->rear=0;
printf("队列初始化成功!\n");
return queue;
}
void in_Queue(PQueue queue,int val)
{
printf("入队开始!\n");
if(isFull(queue))
{
printf("队列已满!\n");
//exit(-1);
}
queue->base[queue->rear]=val;
queue->rear=(queue->rear+1)%6;
printf("入队成功!\n");
}
void out_Queue(PQueue queue)
{
printf("出队开始!\n");
if(isEmpty(queue))
{
printf("队列已空!\n");
}
printf("%d",queue->base[queue->front]);
queue->front=(queue->front+1)%6;
printf("出队成功!\n");
}
void traversal(PQueue queue)
{
int i = queue->front;
printf("遍历开始:\n");
while(i!=queue->rear)
{
printf("%d\n",queue->base[i]);
i=(i+1)%6;
}
printf("遍历结束!\n");
}
int isFull(PQueue queue)
{
if(queue->front==(queue->rear+1)%6)
{
return 1;
}
return 0;
}
int isEmpty(PQueue queue)
{
if(queue->rear==queue->front)
{
return 1;
}
return 0;
}
#include<malloc.h>
typedef struct queue
{
int * base;
int front;
int rear;
}Queue,*PQueue;
PQueue init_Queue(PQueue queue);
void in_Queue(PQueue queue,int val);
void out_Queue(PQueue queue);
void traversal(PQueue queue);
int isFull(PQueue queue);
int isEmpty(PQueue queue);
int main()
{
Queue queue;
PQueue pqueue=init_Queue(&queue);
in_Queue(pqueue,1);
in_Queue(pqueue,2);
in_Queue(pqueue,3);
in_Queue(pqueue,4);
in_Queue(pqueue,5);
traversal(pqueue);
out_Queue(pqueue);
traversal(pqueue);
return 0;
}
PQueue init_Queue(PQueue queue)
{
queue->base=(int *)malloc(sizeof(int)*6);//定义一个数组
queue->front=0;
queue->rear=0;
printf("队列初始化成功!\n");
return queue;
}
void in_Queue(PQueue queue,int val)
{
printf("入队开始!\n");
if(isFull(queue))
{
printf("队列已满!\n");
//exit(-1);
}
queue->base[queue->rear]=val;
queue->rear=(queue->rear+1)%6;
printf("入队成功!\n");
}
void out_Queue(PQueue queue)
{
printf("出队开始!\n");
if(isEmpty(queue))
{
printf("队列已空!\n");
}
printf("%d",queue->base[queue->front]);
queue->front=(queue->front+1)%6;
printf("出队成功!\n");
}
void traversal(PQueue queue)
{
int i = queue->front;
printf("遍历开始:\n");
while(i!=queue->rear)
{
printf("%d\n",queue->base[i]);
i=(i+1)%6;
}
printf("遍历结束!\n");
}
int isFull(PQueue queue)
{
if(queue->front==(queue->rear+1)%6)
{
return 1;
}
return 0;
}
int isEmpty(PQueue queue)
{
if(queue->rear==queue->front)
{
return 1;
}
return 0;
}