#include using namespace std; #define MAX_LENGTH 100 typedef struct TRACK_POINT { int x; int y; }TRACK_POINT; //template class cycleQueue { private: unsigned int m_size; int m_front; int m_rear; TRACK_POINT m_data[MAX_LENGTH]; bool firstPush; bool full_size; public: cycleQueue() {} cycleQueue(unsigned size) :m_size(size), m_front(0), m_rear(0) { //m_data = new TRACK_POINT[size]; full_size = false; firstPush = true; } void set_param(unsigned size) { m_size = size; //m_data = new TRACK_POINT[size]; full_size = false; firstPush = true; m_front = 0; m_rear = 0; } ~cycleQueue() { //delete[] m_data; } bool isEmpty() { return m_front == m_rear; } bool isFull() { return m_front == (m_rear + 1) % m_size; } int getFront() { return m_front; } int getRear() { return m_rear; } int size() { if (full_size) return m_size; else if (m_rear == m_front && firstPush == false) return m_size; else return m_rear - m_front; } void push(TRACK_POINT ele)throw(bad_exception) { if (m_front == m_rear && firstPush==false) { m_front = (m_front + 1) % m_size; full_size = true; //cout << "full_size" << endl; } m_data[m_rear] = ele; m_rear = (m_rear + 1) % m_size; firstPush = false; } TRACK_POINT pop() throw(bad_exception) { if (isEmpty()) { throw bad_exception(); } TRACK_POINT tmp = m_data[m_front]; m_front = (m_front + 1) % m_size; return tmp; } TRACK_POINT& get(int i) { //T tmp = m_data[i]; return m_data[i]; } };