Go to the documentation of this file.
15 #ifndef INCLUDE_SEQQUEUE_HH_
16 #define INCLUDE_SEQQUEUE_HH_
34 class seqQueue :
public Queue<T>
203 : _elem(new value_type[initSize]), _maxSize(initSize), _front(0), _rear(0)
216 return _front == _rear;
222 return ((_rear >= _front) ? _rear - _front : _maxSize + _rear - _front);
228 return _elem[(_front + 1) % _maxSize];
234 return _elem[(_front + 1) % _maxSize];
252 if (size() == _maxSize - 1)
255 _elem[_rear = (_rear + 1) % _maxSize] = val;
261 if (size() == _maxSize - 1)
264 _elem[_rear = (_rear + 1) % _maxSize] = std::move(val);
270 _front = (_front + 1) % _maxSize;
276 value_type *old = _elem;
277 _elem =
new value_type[2 * _maxSize + 1];
279 for (size_type i = 1; i <= size(); ++i)
280 _elem[i] = old[(_front + i) % _maxSize];
285 _maxSize = 2 * _maxSize + 1;
virtual value_type deQueue()
出队一个元素
virtual value_type getHead() const
Get the Head object.
size_type size() const
Returns the number of elements in the queue.
virtual bool isEmpty() const
判队空
void push(const value_type &val)
Inserts a new element at the end of the queue, after its current last element.
bool empty() const
Test whether container is empty.
const typedef value_type & const_reference
数据的常量引用
value_type * _elem
存储元素的内部数组
void pop()
Removes the next element in the queue, effectively reducing its size by one.
size_type _front
队头/尾下标 数据范围(front, rear]: 在循环意义下 初始状态: front == rear == 0 队列满: front == (rear + 1) % maxSize 队列空: fro...
reference & front()
Returns a reference to the next element in the queue.
seqQueue(size_type initSize=10)
Construct a new seq Queue object.
自定义的队列类都在Queue名字空间下(linkQueue.hh)
value_type & reference
数据的引用
value_type & reference
数据的引用
virtual void enQueue(const_reference &x)
入队一个元素
virtual ~seqQueue()
Destroy the seq Queue object.
reference & back()
Returns a reference to the last element in the queue.