-
Notifications
You must be signed in to change notification settings - Fork 0
/
Matrix.h
56 lines (40 loc) · 1.05 KB
/
Matrix.h
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef MATRIXLIB_MATRIX_H
#define MATRIXLIB_MATRIX_H
#include <cstdlib>
#include <iostream>
class Matrix {
public:
static int** matrix;
int m, n;
Matrix(int m, int n){
this->m = m;
this->n = n;
matrix = init(m, n);
}
~Matrix(){
deleteMatrix();
}
void printMatrix() const{
for(int i=0; i<m; i++){
for(int j=0; j<n; j++) {
std::cout << matrix[i][j] << " ";
}
std::cout << "\n";
}
}
private:
static int** init(int rows, int cols){
int** ret = static_cast<int **>(calloc(rows, sizeof(int*)));
for(int i=0; i<rows; i++){
ret[i] = static_cast<int *>(calloc(cols, sizeof(int)));
}
return ret;
}
void deleteMatrix(){
for(int i=0; i<m; i++){
free(matrix[i]);
}
free(matrix);
}
};
#endif //MATRIXLIB_MATRIX_H