-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.h
More file actions
38 lines (28 loc) · 680 Bytes
/
Matrix.h
File metadata and controls
38 lines (28 loc) · 680 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef __MATRIX_H__
#define __MATRIX_H__
#include <iostream>
using namespace std;
template <typename T> class Matrix {
private:
int cols, rows;
T **mat;
public:
Matrix(int cols, int rows) : cols(cols), rows(rows), mat(NULL) {
mat = new T *[rows];
for (int i = 0; i < rows; i++) {
mat[i] = new T[cols];
}
}
~Matrix() {
for (int i = 0; i < this->rows; i++) {
delete[] mat[i];
}
delete[] mat;
}
int getRows() { return this->rows; };
int getCols() { return this->cols; };
T &elem(int r, int c) { return mat[r][c]; };
void print() { cout << "Mat" << rows << "x" << cols; };
T **getMartix() { return mat; };
};
#endif