返回信息流C++没学好 ,这点基础都不知道, 求帮助 [ema1]勿喷啊 ~~~
#include<iostream>
using namespace std;
const int QueueSize = 1000;
template <class T>
class CircleQueue //循环队列模板类
{
private:
T data[QueueSize];
int front; //队头指针
int rear; //队尾指针
public:
CircleQueue(){front = rear = 0;}//构造函数
void EnQueue(T x); //入队
T DeQueue(); //出队
T GetFront(); //查找队头元素
int GetLength(); //求队列长度
bool Empty(){return front == rear?true:false; }//判队空
};
template <class T>
void CircleQueue<T>::EnQueue(T x) //入队
{
if ((rear+1)%QueueSize == front) throw "overflow";
rear = (rear+1)%QueueSize; //队尾指针移向“下”一个位置
data[rear] = x;
};
template <class T>
T CircleQueue<T>::DeQueue() //出队
{
if (rear == front) throw "underflow";
front = (front+1)%QueueSize; //队头指针移向“下”一个位置
return data[front];
};
template <class T>
T CircleQueue<T>::GetFront()//查找队头元素
{
if (rear == front) throw "underflow";
return data[(front+1)%QueueSize];
};
template <class T>
int CircleQueue<T>::GetLength()//求队列长度
{
return (rear-front+QueueSize)%QueueSize;
};
int main()
{
//int a[10]={0,100,200,300,400,500,600,700,800,900};
CircleQueue<int> Q; //使用类模版实例化对象
Q.Empty();
Q.EnQueue(100);
Q.EnQueue(200);
Q.GetFront();
Q.DeQueue();
Q.GetFront();
Q.GetLength();
return 0;
};
编译通过了 就是在main函数里CircleQueue<int> Q; //使用类模版实例化对象 这一句就过不了, 如图
搞了半天不知道这是什么意思?队列到底要怎样才能初始化?可以用数组给它初始化吗?
求大神们帮助~~ 感激不尽[ema16]
这是一条镜像帖。来源:北邮人论坛 / cpp / #84048同步于 2014/11/11
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
#数据结构# 用模版类实现循环队列,不知道怎么在main函数里测
amarlianna
2014/11/11镜像同步3 回复
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复