你能告诉我哪个功能会更快吗?或者也许他们都错了,你知道更好的方法来做到这一点。提前致谢。
double* solveDiagonal(double* A, double* B, int n)
{
double* X = new double[n];
for(int i = 0; i < n; i++)
X[i] = B[i] / A[i*n + i];
return X;
}
double* solveDiagonal(double* A, double* B, int n)
{
double* X = new double[n];
double** pA = new double*[n];
for(int i = 0; i < n; i++)
pA[i] = &A[i*n];
for(int i = 0; i < n; i++)
X[i] = B[i] / pA[i][i];
delete [] pA;
return X;
}