队列(Queue):
特点:先进先出;
基本操作:
一,顺序储存:
1:队的结构体:
typedef struct QNode* PtrToQNode;
typedef int Position;
typedef int NL;
struct QNode{//队列结构体
NL *Data;
Position Front,Rear;//头尾指针
int Maxsize;
};
typedef PtrToQNode Queue;
2:创建空队(队的建立):
Queue CreatQueue(int Maxsize)//创建空队
{
Queue Q=(Queue)malloc(sizeof(struct QNode));
Q->Data=(NL*)malloc(sizeof(NL));
Q->Front=Q->Rear=0;
Q->Maxsize=Maxsize;
printf("空队创建成功\n");
return Q;
}
3:进队操作:
bool IsFull(Queue Q)//判断队是否满
{
return ((Q->Rear+1)%Q->Maxsize==Q->Front);
}
bool AddQ(Queue Q,NL X)//进队操作
{
if(IsFull(Q))
{
printf("队满\n");
return 0;
}
else
{
Q->Rear=(Q->Rear+1)%Q->Maxsize;
Q->Data[Q->Rear]=X;
printf("程序顺利执行:\n");
return 1;
}
}
</