当前位置:   article > 正文

2022/8/30——手动实现c++中的queue类_std::queue 出队失败

std::queue 出队失败

queue类为容器适配器,它给予程序员队列的功能,存储数据特性为先进先出。

类的定义

  1. template <typename T>
  2. class MyQueue
  3. {
  4. private:
  5. T *first;
  6. T *last;
  7. int len;
  8. public:
  9. 函数代码
  10. }

类中包含四大基本函数——析构函数、构造函数、拷贝构造函数、拷贝赋值函数

 析构函数

  1. MyQueue()
  2. {
  3. first = new T[1];
  4. last = first; //说明为空
  5. len = 0;
  6. }

构造函数

  1. ~MyQueue()
  2. {
  3. delete []first;
  4. first = last = NULL;
  5. }

拷贝构造函数

  1. MyQueue(const MyQueue &other)
  2. {
  3. this->len = other.len;
  4. this->first = new T[other.len+1];
  5. memcpy(this->first,other.first,other.len*sizeof (T));
  6. }
拷贝赋值函数
  1. MyQueue &operator=(const MyQueue &other)
  2. {
  3. int size &#
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/777994
推荐阅读
相关标签
  

闽ICP备14008679号