我在 MVC++ 2010 中用 C++ 编写了代码。在其中,程序迭代一维指针数组(双 *)的元素。但是,当我将输入(指针数组的大小)设置为非常大(例如 15000)并运行程序时,它会停止工作并显示一个窗口来关闭程序,因为它没有响应!有什么问题?
这是构建我正在谈论的数组的代码的一部分:
map<int, double *> CF;
CoefficientMap(CF);
double *T = new double[I * J];
for (int r = 1; r <= I * J; ++r)
T[r] = 100;
SOR(T, CF, 1.8);
这是迭代器函数:
void SOR(double *T, map<int, double *> &CF, double w)
{
int iter = 0;
cout << "Stage 2: Solving the linear system of equations using SOR method... ";
const double tol = 0.00001;
double error = tol + 1;
double *TOld = new double[I * J];
for (int i = 1; i <= I * J; ++i)
TOld[i] = 100;
while (abs(error) > tol)
{
++iter;
for (int i = 1; i <= I * J; ++i)
T[i] = (CF[i][0] + CF[i][1] * T[i + 1] + CF[i][2] * T[i + J] + CF[i][3] * T[i - J] + CF[i][4] * T[i - 1]) * w + (1 - w) * T[i];
error = errorCalc(TOld, T, I * J);
for (int i = 1; i <= I * J; ++i)
TOld[i] = T[i];
if (iter % 100 == 0)
{
cout << endl << endl;
cout << "100 iterations done, please wait..." << endl << "Total accumulative error till this point: " << error << endl;
}
if (iter > 10000)
return;
}
cout << "Done!" << endl << endl;
cout << "Converged after " << iter << " iterations!" << endl;
cout << "Final accumulative error: " << error << endl << endl;
}
现在,当 (I * J) 变得足够大(例如 15000)时,程序停止工作!