#includeusing namespace std; //循环顺序队列 template class listQueue { public: listQueue(int _max = 10) { max = _max; Q = new T[max]; tail = 0; head = 0; length = 0; } ~listQueue() { delete[] Q; } //入 void inPut(T elem) { if (length == max) { cout << "队满!" << endl; return; } Q[tail] = elem; tail = (tail + 1) % max; length++; } //出 void outPut(T& elem) { if (length == 0) { cout << "队空!" << endl; return; } elem = Q[head]; head = (head + 1) % max; length--; } //遍历 void print() { int num = head; for(int i = 0; i < length;i++) { cout << i + 1 << " : " << Q[num] << endl; num = (num + 1) % max; } } //取队头元素 T getHead() { if (length == 0) { cout << "队空!" << endl; return (T)NULL; } return Q[head]; } //获取队列长 int getLength() { return length; } private: int max; //队列最大长度 int length; //当前队列长度 int tail; //末尾 int head; //头 T* Q; //队列指针 };



