-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathALGraph.h
executable file
·65 lines (51 loc) · 1.48 KB
/
ALGraph.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
//---------------------------------------------------------------------------
#ifndef ALGRAPH_H
#define ALGRAPH_H
//---------------------------------------------------------------------------
#include <vector>
struct DijkstraInfo
{
unsigned cost;
std::vector<unsigned> path;
};
struct AdjacencyInfo
{
unsigned id;
unsigned weight;
};
typedef std::vector<std::vector<AdjacencyInfo> > ALIST;
class ALGraph
{
public:
ALGraph(unsigned size);
~ALGraph(void);
void AddDEdge(unsigned source, unsigned destination, unsigned weight);
void AddUEdge(unsigned node1, unsigned node2, unsigned weight);
std::vector<DijkstraInfo> Dijkstra(unsigned start_node) const;
ALIST GetAList(void) const;
private:
// An EXAMPLE of some other classes you may want to create and
// implement in ALGraph.cpp
class GNode;
class GEdge;
struct AdjInfo
{
//GNode *node;
unsigned id; // 1..n
unsigned weight;
// helper var for Dijkstra's
unsigned cost;
//AdjInfo();
bool operator<(const AdjInfo& rhs) const {
return weight < rhs.weight;
}
bool operator>(const AdjInfo& rhs) const {
return weight > rhs.weight;
}
};
using ADJLIST = std::vector<std::vector<AdjInfo> >;
// Other private fields and methods
unsigned size_;
ADJLIST alist_;
};
#endif