resize1d.h
来自「数据结构c++语言描述 Borland C++实现」· C头文件 代码 · 共 28 行
H
28 行
// 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 + =
减小字号Ctrl + -
显示快捷键?