题库 C++/C语言题库 题目列表 下面定义了一个循环队列的类,请补全判断队列是否满的...
单选题

下面定义了一个循环队列的类,请补全判断队列是否满的函数,横向上应填写( )。

1 #include <iostream>
2
3 using namespace std;
4
5 class circular_queue {
6 private:
7  int *arr; // 数组用于存储队列元素
8  int capacity; // 队列容量
9  int front; // 队头指针
10  int rear; // 队尾指针
11
12 public:
13  circular_queue(int size) {
14   capacity = size + 1; // 为了避免队列满时与队列空时指针相等的情况,多预留一个空间
15   arr = new int[capacity];
16   front = 0;
17   rear = 0;
18  }
19
20  ~circular_queue() { 
21   delete[] arr;
22  }
23
24  bool is_empty() {
25   return front == rear;
26  }
27
28  bool is_full() {
29   ________________ // 在此处填入代码
30  }
31
32  void en_queue(int data) {
33   if (is_full()) {
34    cout << "队列已满,无法入队!" << endl;
35    return -1;
36   }
37   arr[rear] = data;
38   rear = (rear + 1) % capacity;
39   return 1;
40  }
41
42  int de_queue() {   
43   if (is_empty()) {
44    cout << "队列为空,无法出队!" << endl;
45    return -1; // 出队失败,返回一个特殊值
46   }
47   int data = arr[front];
48   front = (front + 1) % capacity;
49   return data;
50  }
51 };
A.
return (rear + 1) % capacity == front;
B.
return rear % capacity == front;
C.
return rear == front;
D.
return (rear + 1) == front;
题目信息
C++语言等级考试真题 2024年 六级 选择题
-
正确率
0
评论
40
点击