-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.cpp
More file actions
47 lines (41 loc) · 905 Bytes
/
Graph.cpp
File metadata and controls
47 lines (41 loc) · 905 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
/*
* Graph.cpp
*
* Created on: 12 Kas 2015
* Author: Guner
*/
#include "Graph.h"
#include "Edge.h"
Graph::Graph(bool direct = true, int num = 10) :
directed(direct), numV(num) {
vector<Edge> e;
for (int i = 0; i < numV; ++i) {
data.push_back(e);
}
}
void Graph::insert(Edge edge) {
data[edge.getSource()].push_back(edge);
if (!directed) {
data[edge.getDest()].push_back(
Edge(edge.getDest(), edge.getSource(), edge.getWeight()));
}
}
bool Graph::isEdge(int source, int dest) {
if (source < 0) {
return false;/*negative*/
}
for (unsigned int i = 0; i < data[source].size(); ++i) {
if (data[source][i].getDest() == dest) {
return true;
}
}
return false;
}
Edge Graph::getEdge(int source, int dest) {
for (unsigned int i = 0; i < data[source].size(); ++i) {
if (data[source][i].getDest() == dest) {
return data[source][i];
}
}
return Edge(0, 0, 0);
}