跳过正文

数据结构与算法-3-队列

·173 字· loading · loading ·
Masterlong
作者
Masterlong
熬夜,但是世界之夜
目录
数据结构与算法 - 这篇文章属于一个选集。
§ 4: 本文

队列
#

  • Enqueue 入队
  • Dequeue 出队
  • Front 头
    • Headvalue
  • Rear 尾
  • Length

4.3.1 ADT
#

// Abstract queue class
template <typename E> class Queue {
private:
void operator =(const Queue&) {} // Protect assignment
Queue(const Queue&) {} // Protect copy constructor
public:
Queue() {} // Default
virtual ˜Queue() {} // Base destructor
// Reinitialize the queue. The user is responsible for
// reclaiming the storage used by the queue elements.
virtual void clear() = 0;
// Place an element at the rear of the queue.
// it: The element being enqueued.
virtual void enqueue(const E&) = 0;
// Remove and return element at the front of the queue.
// Return: The element at the front of the queue.
virtual E dequeue() = 0;
// Return: A copy of the front element.
virtual const E& frontValue() const = 0;
// Return: The number of elements in the queue.
virtual int length() const = 0;
};

4.3.2 链式
#

两个指针

  • 有队空问题

4.3.3 顺序
#

三个整型变量+一个数组

规定rear指队尾后一位

先操作rear和front,再递增它俩

  • !伪溢出问题
    • 环形队列 求余+1
    • 环形队列 求余 rear不放内容 规避空满异同
    • 设置计数器
数据结构与算法 - 这篇文章属于一个选集。
§ 4: 本文

相关文章

数据结构与算法-2-栈
·191 字· loading · loading
数据结构与算法-1-线性表
·419 字· loading · loading
数据结构与算法-0
·672 字· loading · loading