-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.cpp
More file actions
54 lines (45 loc) · 791 Bytes
/
Copy pathgraph.cpp
File metadata and controls
54 lines (45 loc) · 791 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
#include "graph.h"
graph::graph()
{
this->numNodes = 0;
this->matrix = new int(numNodes*numNodes);
}
graph::graph(int numNodes, char * filename)
{
this->numNodes = numNodes;
this->matrix = new int(numNodes*numNodes);
ifstream ifs(filename);
for (int i = 0; i < numNodes * numNodes; ++i ) {
ifs >> matrix[i];
}
ifs.close();
}
graph::~graph()
{
}
void graph::printMatrix()
{
for (int i = 0;i < numNodes; ++i) {
for (int j = 0; j < numNodes; ++j) {
cout << matrix[numNodes * i + j] << ' ';
}
cout << '\n';
}
}
int graph::getNumNodes()
{
return numNodes;
}
void graph::setNumNodes(int n)
{
numNodes = n;
}
int *graph::getMatrix()
{
return matrix;
}
void graph::setMatrix(int *matrix)
{
delete this->matrix;
this->matrix = matrix;
}