队列特点:
- 先进先出
- 只能从队列头部删除元素
- 只能从队列尾部插入元素
使用:
#include "circlequeue.h"
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
CCircleQueue<int> queue(4);//定义一个容量为4的队列
int i=1;
bool ret;
ret=queue.push_back(i);
if(!ret)
{
cout << "push_back failed" << endl;
}
else
{
cout << "queue.size() = " << queue.size() << ", queue.space() = " << queue.space() << endl;
}
ret=queue.pop_front(0);
if(!ret)
{
cout << "pop_front failed" << endl;
}
else
{
cout << "queue.size() = " << queue.size() << ", queue.space() = " << queue.space() << endl;
}
i=2;
ret=queue.push_back(i);
if(!ret)
{
|