admin 管理员组

文章数量: 1086019


2024年4月30日发(作者:aspects of symmetry)

数据结构循环队列源代码

下面是一个实现循环队列的数据结构的源代码,包括初始化队列、入

队、出队等基本操作。

```C++

#include

using namespace std;

class CircularQueue

private:

int* data; // 存储队列元素的数组

int front; // 队头指针

int rear; // 队尾指针

int capacity; // 队列容量

public:

//构造函数,初始化队列数组、指针和容量

CircularQueue(int size)

data = new int[size];

front = rear = -1;

capacity = size;

}

//判断队列是否为空

bool isEmpt

return (front == -1 && rear == -1);

}

//判断队列是否已满

bool isFul

return ((rear + 1) % capacity == front);

}

//入队操作

void enqueue(int element)

if (isFull()

cout << "队列已满,无法入队!" << endl;

return;

}

if (isEmpty()

front = rear = 0;

} else

rear = (rear + 1) % capacity;

}


本文标签: 队列 数据结构 指针