📄 3.30.c
字号:
◆3.30② 假设将循环队列定义为:以域变量rear
和length分别指示循环队列中队尾元素的位置和内
含元素的个数。试给出此循环队列的队满条件,并
写出相应的入队列和出队列的算法(在出队列的算
法中要返回队头元素)。
实现下列函数:
Status EnCQueue(CLenQueue &Q, QElemType x);
Status DeCQueue(CLenQueue &Q, QElemType &x);
本题的循环队列CLenQueue的类型定义如下:
typedef char QElemType;
typedef struct {
QElemType elem[MAXQSIZE];
int length;
int rear;
} CLenQueue;
Status EnCQueue(CLenQueue &Q, QElemType x)
{ if(Q.length==MAXQSIZE) return ERROR;
Q.elem[Q.rear+1]=x;
Q.rear=(Q.rear+1+MAXQSIZE)%MAXQSIZE;
Q.length++;
return OK;
}
Status DeCQueue(CLenQueue &Q, QElemType &x)
{ int head;
if(Q.length==0) return ERROR;
head=(Q.rear-Q.length+MAXQSIZE+1)%MAXQSIZE;
x=Q.elem[head];
Q.length--;
return OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -