⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resize1d.h

📁 常用算法与数据结构原代码
💻 H
字号:

// change the size of a 1D array

#include "xcept.h"

template<class T>
void ChangeSize1D(T * &a, int n, int ToSize)
{// Change the size of the one-dimensional
 // array a to ToSize.  n is the number
 // of elements in the array at present.

   // make sure new size is adequate
   if (n > ToSize) throw BadInput();

   // allocate a new array of desired size
   T *temp = new T [ToSize];

   // copy from old space to new space
   for (int i = 0; i < n; i++)
      temp[i] = a[i];

   // free old space
   delete [] a;

   // make a point to new space
   a = temp;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -