Commit bf14c166 authored by CDK6182CHR's avatar CDK6182CHR
Browse files

2021.5.20

parent 22a66b31
{
"files.associations": {
"*.pyetlib": "json",
"*.pyetgr": "json",
"atomic": "cpp",
"cctype": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"functional": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"memory": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"utility": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocnum": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xutility": "cpp"
}
}
\ No newline at end of file
#include <iostream>
#include <utility>
/**
* 二维数组的简单封装,使用连续空间,运算下标
*/
template <typename T>
class Matrix {
int row, col;
T* data;
public:
Matrix(int row_, int col_);
~Matrix();
T& get(int i, int j);
T* get_pointer(int i, int j);
inline T* get_pointer_serial(int n) {
return data + n;
}
inline const T& get(int i, int j)const {
return const_cast<Matrix*>(this)->get(i, j);
}
inline int get_row()const {
return row;
}
inline int get_col()const {
return col;
}
void fill(const T& d);
Matrix(const Matrix&) = delete;
Matrix(Matrix&&) = delete;
Matrix& operator=(const Matrix&) = delete;
Matrix& operator=(Matrix&&) = delete;
void show()const;
};
template<typename T>
Matrix<T>::Matrix(int row_, int col_):row(row_),col(col_)
{
data = new T[row * col];
}
template<typename T>
Matrix<T>::~Matrix()
{
delete[] data;
data = nullptr;
}
template<typename T>
T& Matrix<T>::get(int i, int j)
{
return data[i * col + j];
}
template<typename T>
T* Matrix<T>::get_pointer(int i, int j)
{
return data + i * col + j;
}
template<typename T>
void Matrix<T>::fill(const T& d)
{
std::fill(data, data + row * col, d);
}
template<typename T>
void Matrix<T>::show() const
{
std::cout << '[' << std::endl;
for (int i = 0; i < row; i++) {
std::cout << ' ';
for (int j = 0; j < col; j++) {
std::cout << get(i, j) << ' ';
}
std::cout << std::endl;
}
std::cout << ']' << std::endl;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment