-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.cpp
70 lines (52 loc) · 1.27 KB
/
node.cpp
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
/*** Implements the node.h class, for representing the nodes of the Query graph
*** Is also the base class for Vertex class defined in vertex.h
***/
#include "node.h"
#include <iostream>
// Constructs a vertex with the corresponding characteristics
// Sets the ID and the label of a vertex
Node :: Node(string id, string lab) : ID(id), label(lab)
{
neighbourIDs.clear();
}
// Deallocates space
Node :: ~Node()
{
neighbourIDs.clear();
}
// Returns vertex label
const string Node :: getLabel(void) const
{
return label;
}
// Returns vertex ID
const string Node :: getID(void) const
{
return ID;
}
// Returns the ID list of the neighbouring vertices
const set<string>& Node :: getNeighbourIDs(void) const
{
return neighbourIDs;
}
// Add the IDs of adjacent vertices
void Node :: addNeighbours(set<string>& neigh)
{
set<string>::iterator it = neigh.begin();
for(; it != neigh.end(); it++)
neighbourIDs.insert(*it);
}
// Add the ID of one adjacent vertex
void Node :: addNeighbours(string neigh)
{
neighbourIDs.insert(neigh);
}
// Prints the node characteristics
void Node :: print(void) const
{
cout<<"ID: "<<ID<<"\tLabel: "<<label<<"\tNeighbourIDs: ";
set<string>::iterator it = neighbourIDs.begin();
for(; it!=neighbourIDs.end(); it++)
cout<<*it<<" ";
cout<<endl;
}