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

📄 zmatrix.h

📁 数据结构c++语言描述 Borland C++实现
💻 H
字号:


// Z-matrix

#ifndef ZMatrix_
#define ZMatrix_

#include <stdlib.h>
#include <iostream.h>
#include "xcept.h"


template<class T>
class ZMatrix {
   public:
      ZMatrix(int size = 10)
         {n = size; t = new T [3*n-2];}
      ~ZMatrix() {delete [] t;}
      ZMatrix<T>& Store(const T& x, int i, int j);
      T Retrieve(int i, int j);
   private:
      int n;    // dimension
      T *t;     // 1D array
};

template<class T>
ZMatrix<T>& ZMatrix<T>::
     Store(const T& x, int i, int j)
{// Store x as N(i,j).
   if ( i < 1 || j < 1 || i > n || j > n)
       throw OutOfBounds();
   if (i == 1) t[j-1] = x;          // first row
   else if (i == n) t[n+j-1] = x;   // last row
        else if (i+j == n+1) t[2*n+i-2] = x;
                   // rest of cross diagonal
             else if (x != 0) throw MustBeZero();
   return *this;
}
  
template <class T>
T ZMatrix<T>::Retrieve(int i, int j)
{// Retrieve C(i,j)
   if ( i < 1 || j < 1 || i > n || j > n)
       throw OutOfBounds();
   if (i == 1) return t[j-1];   // first column
   if (i == n) return t[n+j-1]; // last column
   if (i+j == n+1) return t[2*n+i-2]; 
             // rest of cross diagonal
   return 0; // outside the Z
}

#endif

⌨️ 快捷键说明

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