-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graph.h
75 lines (62 loc) · 1.3 KB
/
Graph.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// Created by eden on 16/01/2020.
//
#ifndef EX4__GRAPH_H_
#define EX4__GRAPH_H_
using namespace std;
#include <vector>
#include <string>
#include <iostream>
#include "State.h"
//the type of the values
template<class T>
class Graph{
private:
vector<vector<string>> stringMatrix;
int numOfRows;
int numOfColumns;
public:
Graph(vector<string> vec) {
for (int i = 0; i < vec.size(); i++) {
addRow(vec.at(i));
}
this->numOfRows = this->stringMatrix.size() - 2;
this->numOfColumns = this->stringMatrix.at(0).size();
};
void addRow(string s) {
vector<string> temp;
int len = s.length();
int i = 0, j;
while (i < len) {
if (s.at(i)==' ' || s.at(i)==',') {
i++;
continue;
} else {
j = i;
string ch = "";
while (s.at(j)!=' ' && s.at(j)!=',') {
ch += (s.at(j));
j++;
if (j==len) {
break;
}
}
temp.push_back(ch);
}
i = j;
}
if (s!="" && s.compare("\r")!=0) {
this->stringMatrix.push_back(temp);
}
}
int getNumOfRows() {
return this->numOfRows;
}
int getNumOfColumns() {
return this->numOfColumns;
}
vector<vector<string>> getStringMatrix() {
return this->stringMatrix;
}
};
#endif //EX4__GRAPH_H_