码迷,mamicode.com
首页 > 其他好文 > 详细

队列扩容

时间:2019-06-07 23:01:35      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:parameter   判断   iter   city   isa   include   caller   aci   pass   

template<class T>
void Queue<T>::Push(const T& item)
{
  /*if (rear == capacity-1)
  {
    rear = 0;
  }
  else
  {
    rear++;
  }*/

  //判断队列是否存满
  if ((rear+1)%capacity == front)
  {
    //加倍
    T* newQueue = new T[2*capacity];
    //判断是否发生回绕
    int start = (front + 1) % capacity;
    if (start<2)
    {
      std::copy(queue+start,queue+start+capacity-1,newQueue);
    }
    else
    {
      std::copy(queue+start,queue+capacity,newQueue);
      std::copy(queue,queue+rear+1,newQueue+capacity-start);
    }

    front = 2 * capacity;
    rear = capacity - 2;
    capacity *= 2;
    delete[] queue;
    queue = newQueue;
  }

  rear = (rear + 1) % capacity;
  queue[rear] = item;
}

 

------------------------------------------------------------------------------------

严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C4996 ‘std::copy::_Unchecked_iterators::_Deprecate‘: Call to ‘std::copy‘
with parameters that may be unsafe - this call relies on the caller to c
heck that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ ‘Checked Iterators‘ 34_顺序队列 e:\visual studio 2015\install\vc\include\xutility 2372

 

属性-> c/c++ -> 预处理器 -> 预处理器定义 里添加 
_SCL_SECURE_NO_WARNINGS

 

队列扩容

标签:parameter   判断   iter   city   isa   include   caller   aci   pass   

原文地址:https://www.cnblogs.com/herd/p/10989250.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!