- 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;
- };
本文转自eyjian 51CTO博客,原文链接:http://blog.51cto.com/mooon/904971,如需转载请自行联系原作者