-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvertex.cpp
More file actions
57 lines (45 loc) · 1.18 KB
/
vertex.cpp
File metadata and controls
57 lines (45 loc) · 1.18 KB
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
#include "vertex.hpp"
using namespace csce;
using namespace std;
Vertex::Vertex(size_t id) : _id(id) { }
Vertex &Vertex::addNeighbor(size_t id) {
return this->addNeighbor(Vertex(id));
}
Vertex &Vertex::addNeighbor(const Vertex& vertex) {
this->_neighbors.push_back(vertex);
return *this;
}
size_t Vertex::getDegree() const {
return this->_neighbors.size();
}
size_t Vertex::getId() const {
return this->_id;
}
list<Vertex> Vertex::getNeighbors() const {
return this->_neighbors;
}
bool Vertex::hasNeighbor(size_t id) const {
return this->hasNeighbor(Vertex(id));
}
bool Vertex::hasNeighbor(const Vertex& vertex) const {
auto neighbor = this->_neighbors.begin();
for (neighbor; neighbor != this->_neighbors.end(); neighbor++) {
if (*neighbor == vertex) {
break;
}
}
return neighbor != this->_neighbors.end();
}
Vertex &Vertex::removeNeighbor(size_t id) {
this->removeNeighbor(Vertex(id));
return *this;
}
Vertex &Vertex::removeNeighbor(const Vertex& vertex) {
this->_neighbors.remove(vertex);
return *this;
}
string Vertex::str() const {
ostringstream oss;
oss << this->_id;
return oss.str();
}