-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMatrix.h
More file actions
55 lines (48 loc) · 790 Bytes
/
Matrix.h
File metadata and controls
55 lines (48 loc) · 790 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Matrix.h
ʹÓÃvectorʵÏÖ¾ØÕó
2016/10/12
*/
#ifndef MATRIX_H_
#define MATRIX_H_
#include <vector>
#include <algorithm>
using std::vector;
template<typename Object>
class matrix
{
public:
matrix(int rows, int cols) :
array{rows}
{
for (auto & thisRow: array)
{
thisRow.resize(cols);
}
}
matrix(const vector<vector<Object>> & v)
:array{v}
{}
matrix(vector<vector<Object>> && v)
:array{std::swap(v)}
{}
vector<Object>& operator[](int row)
{
return array[row];
}
const vector<Object>& operator[](int row) const
{
return array[row];
}
int rows() const
{
return array.size();
}
int cols() const
{
return rows() == 0 ? 0 : array[0].size();
}
private:
vector<vector<Object>> array;
};
#endif