-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix.h
46 lines (36 loc) · 857 Bytes
/
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
#ifndef MATRIX_H
#define MATRIX_H
#include "stl.h"
template<typename T> struct Matrix
{
// init
Matrix(int _nrow, int _ncol){ setDim(_nrow, _ncol); }
Matrix(){}
// set dimension
void setDim(int _nrow, int _ncol){
for (int i=0; i < (int)value.size(); i++)
value[i].clear();
value.clear();
nrow = _nrow;
ncol = _ncol;
for (int i=0; i<nrow; i++){
vector<T> cur_value;
for (int j=0; j<ncol; j++){
T cur_cell;
cur_value.push_back(cur_cell);
}
value.push_back(cur_value);
}
}
// define operator
vector<T> & operator[](const int i)
{
return value[i];
}
// cell value
vector<vector<T> > value;
// dimension
int nrow;
int ncol;
};
#endif // MATRIX