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

📄 diag.h

📁 一本全面剖析C++数据结构算法的书籍
💻 H
字号:
// file diag.h#ifndef DiagonalMatrix_#define DiagonalMatrix_// diagonal matrix#include <stdlib.h>#include <iostream.h>#include "xcept.h"template<class T>class DiagonalMatrix {   public:      DiagonalMatrix(int size = 10)         {n = size; d = new T [n];}      ~DiagonalMatrix() {delete [] d;} // destructor      DiagonalMatrix<T>&         Store(const T& x, int i, int j);      T Retrieve(int i, int j) const;   private:      int n; // matrix dimension      T *d;  // 1D array for diagonal elements};template<class T>DiagonalMatrix<T>& DiagonalMatrix<T>::             Store(const T& x, int i, int j){// Store x as D(i,j).   if (i < 1 || j < 1 || i > n || j > n)       throw OutOfBounds();   if (i != j && x != 0) throw MustBeZero();   if (i == j) d[i-1] = x;   return *this;}  template <class T>T DiagonalMatrix<T>::Retrieve(int i, int j) const{// Retrieve D(i,j).   if (i < 1 || j < 1 || i > n || j > n)       throw OutOfBounds();   if (i == j) return d[i-1];   else return 0;}#endif

⌨️ 快捷键说明

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