第一种办法是在前面加
SeqQueue(int sz = 10);
~SeqQueue(){delete []elements;}
bool isFull(){return ((rear + 1) % maxSize ==
front)? true: false;} //判断队列是否满
bool isEmpty(){return (front == rear)? true:
false;} //判断队列是否空
bool EnQueue(const T& x);
//入列
bool DeQueue(); //出列
friend
ostream&
operator<<<T>(ostream&
os, SeqQueue<T>& Q);
//重载栈中元素的输出操作
int rear, front; //队尾;队头指针
int maxSize, tag; //队列最大可容纳的元素个数;标记
T* elements; //存放队列元素的数组
int num;
if(Q.front==Q.rear
&& Q.tag==1)
num=Q.maxSize;
else
num=(Q.rear - Q.front +
Q.maxSize) % Q.maxSize;
for(int i = Q.front; i != Q.rear; i = (i + 1) %
Q.maxSize)
os<<i<<":"<<Q.elements[i]<<endl;
return os;
第二种方法,就是直接在模板中实现在,即:
template
class Array{
public:
........something......
friend ostream& operator<< (ostream& out,Array&rhs){
.......something.....
}
};
template <class
T>
class SeqQueue;
template <class
T>
std::ostream& operator
<<(std::ostream& os,
SeqQueue<T>&
Q);
//顺序队列的定义
template <class T>
class SeqQueue{
public:
protected:
};
template <class
T>
ostream&
operator<<(ostream&
os, SeqQueue<T>&
Q){
}
第二种方法,就是直接在模板中实现在,即:
template
class Array{
public:
........something......
friend ostream& operator<< (ostream& out,Array&rhs){
.......something.....
}
};