数组队列C++实现
template <typename _T>
class CArrayQueue {
public:
CArrayQueue() {
m_rear = 0;
m_front = 0;
m_array = new _T[m_num];
}
bool full() const
{
return ((m_rear+1) % m_num == m_front);
}
bool empty() const
{
return (m_front == m_rear);
}
void push(const _T& t) {
array[m_rear] = t;
m_rear = (m_rear+1) % m_num;
}
_T& pop() {
_T& t= array[m_front];
m_front = (m_front+1) % m_num;
return t;
}
private:
_T* array;
int m_rear;
int m_front;
};
class CArrayQueue {
public:
CArrayQueue() {
m_rear = 0;
m_front = 0;
m_array = new _T[m_num];
}
bool full() const
{
return ((m_rear+1) % m_num == m_front);
}
bool empty() const
{
return (m_front == m_rear);
}
void push(const _T& t) {
array[m_rear] = t;
m_rear = (m_rear+1) % m_num;
}
_T& pop() {
_T& t= array[m_front];
m_front = (m_front+1) % m_num;
return t;
}
private:
_T* array;
int m_rear;
int m_front;
};
相关热门文章