队列
#include<stdio.h>
#include<stdlib.h>
struct queue{
int Data[100];
int Rear;
int Front;
};
void Createqueue(struct queue *q)
{
q->Rear = -1;
q->Front = -1;
}
void Addqueue(struct queue *q, int x)//in queue
{
q->Rear++;
q->Data[q->Rear] = x;
}
int Outqueue(struct queue *q)
{
q->Front++;
return q->Data[q->Front];
}
int Isqueue(struct queue *q) //判断队列是否队空
{
int i;
if(q->Rear == q->Front) {
i = 0;
}
else {
i = 1;
}
return i;
}
int main()
{
struct queue Qa;
Createqueue(&Qa);
for(int i = 0;i<9;i++)
{
Addqueue(&Qa,i);
}
while(Isqueue(&Qa))
{
int k = Outqueue(&Qa);
printf("%d",k);
}
}