#include<stdio.h>
#include<malloc.h>
typedef struct queue
{
int * Base;
int front;
int rear;
} QUEUE,*pQUEUE;
bool init(pQUEUE);
bool enter_queue(pQUEUE,int val);
bool full_queue(pQUEUE);
bool empty_queue(pQUEUE);
bool out_queue(pQUEUE);
bool traverse(pQUEUE);
int main()
{
QUEUE my;
init(&my);
enter_queue(&my,1);
enter_queue(&my,2);
enter_queue(&my,3);
enter_queue(&my,4);
enter_queue(&my,5);
traverse(&my);
out_queue(&my);
out_queue(&my);
traverse(&my);
return 0;
}
bool init(pQUEUE T)
{
T->Base=(int*)malloc(sizeof(int)*6);
if(T->Base==NULL)
return false;
T->front=0;
T->rear=0;
return true;
}
bool enter_queue(pQUEUE T,int val)
{
if(full_queue(T))
return false;
T->Base[T->rear%6]=val;
T->rear++;
return true;
}
bool full_queue(pQUEUE T)
{
if((T->rear+1)%6==T->front)
return true;
return false;
}
bool empty_queue(pQUEUE T)
{
if(T->front==T->rear)
return true;
return false;
}
bool traverse(pQUEUE T)
{
if(empty_queue(T))
return false;
for(int i=T->front;i!=T->rear;i=(i+1)%6)
printf("%d\n",T->Base[i]);
return true;
}
bool out_queue(pQUEUE T)
{
if(empty_queue(T))
return false;
T->front=(T->front+1)%6;
return true;
}
#include<malloc.h>
typedef struct queue
{
int * Base;
int front;
int rear;
} QUEUE,*pQUEUE;
bool init(pQUEUE);
bool enter_queue(pQUEUE,int val);
bool full_queue(pQUEUE);
bool empty_queue(pQUEUE);
bool out_queue(pQUEUE);
bool traverse(pQUEUE);
int main()
{
QUEUE my;
init(&my);
enter_queue(&my,1);
enter_queue(&my,2);
enter_queue(&my,3);
enter_queue(&my,4);
enter_queue(&my,5);
traverse(&my);
out_queue(&my);
out_queue(&my);
traverse(&my);
return 0;
}
bool init(pQUEUE T)
{
T->Base=(int*)malloc(sizeof(int)*6);
if(T->Base==NULL)
return false;
T->front=0;
T->rear=0;
return true;
}
bool enter_queue(pQUEUE T,int val)
{
if(full_queue(T))
return false;
T->Base[T->rear%6]=val;
T->rear++;
return true;
}
bool full_queue(pQUEUE T)
{
if((T->rear+1)%6==T->front)
return true;
return false;
}
bool empty_queue(pQUEUE T)
{
if(T->front==T->rear)
return true;
return false;
}
bool traverse(pQUEUE T)
{
if(empty_queue(T))
return false;
for(int i=T->front;i!=T->rear;i=(i+1)%6)
printf("%d\n",T->Base[i]);
return true;
}
bool out_queue(pQUEUE T)
{
if(empty_queue(T))
return false;
T->front=(T->front+1)%6;
return true;
}