#include<stdio.h>
#include<stdlib.h>
#define ERROR 0
#define OK 1
#define MaxSize 20
typedef int ElementType;
typedef int Status;
struct QNode
{
ElementType Data[MaxSize];
int rear;
int front;
//front 指向队列中队首的前一个
};
typedef struct QNode *Queue;
/**
* 将元素放入队列
* */
void AddQ(Queue Q,ElementType item)
{
//1.先判断队列是否已满,满退出
if((Q->rear+1) % MaxSize == Q->front)
{
printf("队列满");
return;
}
//2.如果没满,将元素放在rear+1处
else
{
Q->Data[++Q->rear] = item;
}
}
/**
* 将元素弹出队列
* */
ElementType DeleteQ(Queue PtrQ)
{
if(PtrQ->front == PtrQ->rear)
{
printf("队列空");
return ERROR;
}
else
{
PtrQ->front = (PtrQ->front + 1) % MaxSize;
return PtrQ->Data[PtrQ->front];
}
}
C语言队列的顺序存储结构,入队和出队
最新推荐文章于 2023-03-21 20:35:53 发布