队列类模板
#ifndef QUENE_H
#define QUENE_H
#include <cassert>
template<class T, int SIZE = 50>
class Quene {
private:
int front, rear, count;
T list[SIZE];
public:
Quene();
void insert(const T& item);
T remove();
void clear();
const T& getFront() const;
int getLength() const;
bool isEmpty() const;
bool isFull() const;
};
template<class T, int SIZE>
Quene<T, SIZE>::Quene() : front(0), rear(0), count(0) {};
template<class T, int SIZE>
void Quene<T, SIZE>::insert(const T& item) {
assert(count != SIZE);
count++;
list[rear] = item;
rear = (rear + 1) % SIZE;
}
template<class T, int SIZE>
T Quene<T, SIZE>::remove() {
assert(count != 0);
count--;
int temp = front;
front = (front + 1) % SIZE;
return list[temp];
}
template<class T, int SIZE>
void Quene<T, SIZE>::clear() {
front = 0;
rear = 0;
count = 0;
}
template<class T, int SIZE>
const T& Quene<T, SIZE>::getFront() const {
return list[front];
}
template<class T, int SIZE>
int Quene<T, SIZE>::getLength() const {
return count;
}
template<class T, int SIZE>
bool Quene<T, SIZE>::isFull() const {
return count == SIZE;
}
template<class T, int SIZE>
bool Quene<T, SIZE>::isEmpty() const {
return count == 0;
}
#endif