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

📄 dynarrays.cpp

📁 C++ Math Lib. C++ Builder must use.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  };

  for(int i1 = l1; i1 < h1; i1++ )
  {
    q = this->operator() (i1);
    if (q > amax) amax = q;
    if (q < amin) amin = q;
  };
};


// FArr2D =============================================================

// Default Constructor: Creates a 1 by 1 matrix; sets value to zero.
FArr2D::FArr2D(){
  dd = 1;
  data = new double [dd];  // Allocate memory
  fill(0.0);                // Set value of data_[0] to 0.0
}

// 1-based Constructor: Creates an aD1 by aD1 matrix; sets values to zero.
FArr2D::FArr2D(int aD1, int aD2) : Lim2D(aD1, aD2)
{
  dd = d1*d2;
  data = new double [dd];  // Allocate memory
  assert(data != 0);          // Check that memory was allocated
  fill(0.0);                  // Set values of data_[] to 0.0
}

// General Constructor: Creates an aD1 by aD1 matrix; sets values to zero.
FArr2D::FArr2D(int aL1, int aH1, int aL2, int aH2) : Lim2D(aL1, aH1, aL2, aH2)
{
  dd = d1*d2;
  data = new double [dd];  // Allocate memory
  assert(data != 0);          // Check that memory was allocated
  fill(0.0);                  // Set values of data_[] to 0.0
}

// Fills all elements of a matrix to a given value.
void FArr2D::fill(double value) {
  for(int i = 0; i < dd; i++ ) data[i] = value;
}

// Private copy function: Copies values from one FArr2D object to another.
void FArr2D::copy(const FArr2D& mat) {
  Lim2D::copy(mat);
  dd = mat.dd;
  data = new double [dd];
  for(int i = 0; i < dd; i++ ) data[i] = mat.data[i];
}

void FArr2D::swap1(int i1, int j1)
{
  double t;
  int i = d2*(i1-l1);
  int j = d2*(j1-l1);
  for (int k = 0; k < d2; k++ )
  {
    t = data[i+k];
    data[i+k] = data[j+k];
    data[j+k] = t;
  };
};

void FArr2D::swap2(int i2, int j2)
{
  double t;
  int i = (i2-l1);
  int j = (j2-l1);
  for (int k = 0; k < d1; k++ )
  {
    t = data[i];
    data[i] = data[j];
    data[j] = t;
    i += d2;  j += d2;
  };
};

// IArr1D =============================================================

// Default Constructor: Creates a 1 - vector; sets value to zero.
IArr1D::IArr1D()
{
  dd = d1;
  data = new int [dd];  // Allocate memory
  fill(0.0);               // Set value of data_[0] to 0.0
}

// 1-based Constructor: Creates an aD1 - vector; sets values to zero.
IArr1D::IArr1D(int aD1) : Lim1D(aD1)
{
  dd = d1;
  data = new int [dd];  // Allocate memory
  assert(data != 0);          // Check that memory was allocated
  fill(0.0);                  // Set values of data_[] to 0.0
}

// General Constructor: Creates an aD1 - vector; sets values to zero.
IArr1D::IArr1D(int aL1, int aH1) : Lim1D(aL1, aH1)
{
  dd = d1;
  data = new int [dd];  // Allocate memory
  assert(data != 0);          // Check that memory was allocated
  fill(0.0);                  // Set values of data_[] to 0.0
}

// Fills all elements of a matrix to a given value.
void IArr1D::fill(int value) {
  for(int i = 0; i < dd; i++ ) data[i] = value;
}

// Protected copy function: Copies values from one IArr1D object to another.
void IArr1D::copy(const IArr1D& vec)
{
  Lim1D::copy(vec);
  dd = vec.dd;
  data = new int [dd];
  for(int i = 0; i < dd; i++ ) data[i] = vec.data[i];
}
void IArr1D::swap1(int i1, int j1)
{
  int temp = data[ (i1-l1) ];
  data[ (i1-l1) ] = data[ (j1-l1) ];
  data[ (j1-l1) ] = temp;
};

// IArr2D =============================================================

// Default Constructor: Creates a 1 by 1 matrix; sets value to zero.
IArr2D::IArr2D(){
  dd = 1;
  data = new int [dd];  // Allocate memory
  fill(0.0);                // Set value of data_[0] to 0.0
}

// 1-based Constructor: Creates an aD1 by aD1 matrix; sets values to zero.
IArr2D::IArr2D(int aD1, int aD2) : Lim2D(aD1, aD2)
{
  dd = d1*d2;
  data = new int [dd];  // Allocate memory
  assert(data != 0);          // Check that memory was allocated
  fill(0.0);                  // Set values of data_[] to 0.0
}

// General Constructor: Creates an aD1 by aD1 matrix; sets values to zero.
IArr2D::IArr2D(int aL1, int aH1, int aL2, int aH2) : Lim2D(aL1, aH1, aL2, aH2)
{
  dd = d1*d2;
  data = new int [dd];  // Allocate memory
  assert(data != 0);          // Check that memory was allocated
  fill(0.0);                  // Set values of data_[] to 0.0
}

// Fills all elements of a matrix to a given value.
void IArr2D::fill(int value) {
  for(int i = 0; i < dd; i++ ) data[i] = value;
}

// Private copy function: Copies values from one IArr2D object to another.
void IArr2D::copy(const IArr2D& mat) {
  Lim2D::copy(mat);
  dd = mat.dd;
  data = new int [dd];
  for(int i = 0; i < dd; i++ ) data[i] = mat.data[i];
}


// FArr3D =============================================================

// Default Constructor: Creates a 1 by 1 matrix; sets value to zero.
FArr3D::FArr3D(){
  dd = 1;
  data = new double [dd];  // Allocate memory
  fill(0.0);                // Set value of data_[0] to 0.0
}

// 1-based Constructor: Creates an aD1 by aD1 matrix; sets values to zero.
FArr3D::FArr3D(int aD1, int aD2, int aD3) : Lim3D(aD1, aD2, aD3)
{
  dd = d1*d2*d3;
  data = new double [dd];  // Allocate memory
  assert(data != 0);          // Check that memory was allocated
  fill(0.0);                  // Set values of data_[] to 0.0
}

// General Constructor: Creates an aD1 by aD1 matrix; sets values to zero.
FArr3D::FArr3D(int aL1, int aH1, int aL2, int aH2, int aL3, int aH3)
      : Lim3D(aL1, aH1, aL2, aH2, aL3, aH3)
{
  dd = d1*d2*d3;
  data = new double [dd];  // Allocate memory
  assert(data != 0);          // Check that memory was allocated
  fill(0.0);                  // Set values of data_[] to 0.0
}

// Fills all elements of a matrix to a given value.
void FArr3D::fill(double value) {
  for(int i = 0; i < dd; i++ ) data[i] = value;
}

// Private copy function: Copies values from one FArr2D object to another.
void FArr3D::copy(const FArr3D& mat) {
  Lim3D::copy(mat);
  dd = mat.dd;
  data = new double [dd];
  for(int i = 0; i < dd; i++ ) data[i] = mat.data[i];
}

void FArr3D::GetFArr2D(int i1, FArr2D& m)
{
  double t;
  int k = d3*d2*(i1-l1);
  for (int i2 = l2; i2 <= h2; i2++ )
    for (int i3 = l3; i3 <= h3; i3++ )
    {
  //    data[ d3*d2*(i1-l1) + d3*(i2-l2) + (i3-l3) ]
      m(i2,i3) = data[ k++ ];
    };
};

void FArr3D::SetFArr2D(int i1, FArr2D& m)
{
  double t;
  int k = d3*d2*(i1-l1);
  for (int i2 = l2; i2 <= h2; i2++ )
    for (int i3 = l3; i3 <= h3; i3++ )
    {
//      data[ d3*d2*(i1-l1) + d3*(i2-l2) + (i3-l3) ]
      data[ k++ ] = m(i2,i3);
    };
};


// Sparse2D =============================================================

// Default Constructor: Creates a 1 by 1 matrix; sets value to zero.
Sparse2D::Sparse2D(){
  dd = 1;
  data = new double [dd];  // Allocate memory
  fill(0.0);                // Set value of data_[0] to 0.0
}

// 1-based Constructor: Creates an aD1 by aD1 matrix; sets values to zero.
Sparse2D::Sparse2D(int aD1, int aD2) : Lim2D(aD1, aD2)
{
  dd = d1*d2;
  data = new double [dd];  // Allocate memory
  assert(data != 0);          // Check that memory was allocated
  fill(0.0);                  // Set values of data_[] to 0.0
}

// General Constructor: Creates an aD1 by aD1 matrix; sets values to zero.
Sparse2D::Sparse2D(int aL1, int aH1, int aL2, int aH2) : Lim2D(aL1, aH1, aL2, aH2)
{
  dd = d1*d2;
  data = new double [dd];  // Allocate memory
  assert(data != 0);          // Check that memory was allocated
  fill(0.0);                  // Set values of data_[] to 0.0
}

// Fills all elements of a matrix to a given value.
void Sparse2D::fill(double value) {
  for(int i = 0; i < dd; i++ ) data[i] = value;
}

// Private copy function: Copies values from one Sparse2D object to another.
void Sparse2D::copy(const Sparse2D& mat) {
  Lim2D::copy(mat);
  dd = mat.dd;
  data = new double [dd];
  for(int i = 0; i < dd; i++ ) data[i] = mat.data[i];
}


// Sparse3D =============================================================

// Default Constructor: Creates a 1 by 1 matrix; sets value to zero.
Sparse3D::Sparse3D(){
  dd = 1;
  data = new double [dd];  // Allocate memory
  fill(0.0);                // Set value of data_[0] to 0.0
}

// 1-based Constructor: Creates an aD1 by aD1 matrix; sets values to zero.
Sparse3D::Sparse3D(int aD1, int aD2, int aD3) : Lim3D(aD1, aD2, aD3)
{
  dd = d1*d2*d3;
  data = new double [dd];  // Allocate memory
  assert(data != 0);          // Check that memory was allocated
  fill(0.0);                  // Set values of data_[] to 0.0
}

// General Constructor: Creates an aD1 by aD1 matrix; sets values to zero.
Sparse3D::Sparse3D(int aL1, int aH1, int aL2, int aH2, int aL3, int aH3)
      : Lim3D(aL1, aH1, aL2, aH2, aL3, aH3)
{
  dd = d1*d2*d3;
  data = new double [dd];  // Allocate memory
  assert(data != 0);          // Check that memory was allocated
  fill(0.0);                  // Set values of data_[] to 0.0
}

// Fills all elements of a matrix to a given value.
void Sparse3D::fill(double value) {
  for(int i = 0; i < dd; i++ ) data[i] = value;
}

// Private copy function: Copies values from one Sparse2D object to another.
void Sparse3D::copy(const Sparse3D& mat) {
  Lim3D::copy(mat);
  dd = mat.dd;
  data = new double [dd];
  for(int i = 0; i < dd; i++ ) data[i] = mat.data[i];
}

// ===================================================================



⌨️ 快捷键说明

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