-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdjacencyLists.h
68 lines (59 loc) · 1.04 KB
/
AdjacencyLists.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
#ifndef ADJACENCYLISTS_H_
#define ADJACENCYLISTS_H_
#include <set>
namespace wangbb
{
class AdjacencyLists
{
protected:
int n;
std::set<int> *adj;
public:
AdjacencyLists(int n0)
{
n = n0;
adj = new set::set<int>[n];
}
virtual ~AdjacencyLists()
{
delete [] adj;
}
void addEdge(int i, int j)
{
adj[i].add(j);
}
bool hasEdge(int i, int j)
{
return adj[i].contains(j);
}
void inEdges(int i, std::set<int> &edges)
{
for (int j = 0; j < n; j++)
{
if (adj[j].contains(i))
{
edges.insert(j);
}
}
}
int nVertices()
{
return n;
}
void outEdges(int i, std::set<int> &edges)
{
for (auto it = adj[i].begin(); it != adj[i].end(); ++it)
{
edges.add(*it);
}
}
void removeEdge(int i, int j)
{
if (adj[i].contains(j))
{
adj[i].erase(j);
}
}
};
}
#endif /* ADJACENCYLISTS_H_ */