-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPrim.h
45 lines (40 loc) · 1.25 KB
/
Prim.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
#ifndef __PRIM_H__
#define __PRIM_H__
#include <iostream>
#include "internal.h"
#include "FibHeap.h"
class Prim {
private:
AdjList adj;
EdgeSet edges;
EdgeSet min_spanning_tree;
FibHeapPtr fib_heap = nullptr;
int mst_cost = 0;
unsigned next_id = 0;
bool status_finished = false;
public:
Prim();
~Prim();
FibNodePtr PrimAddVertex(unsigned id=UINT_MAX);
int PrimAddEdge(unsigned u, unsigned v);
int PrimMinSpanningTree(int (*weight)(unsigned u, unsigned v),
unsigned root);
int PrimGetMSTCost(void) { return mst_cost; }
EdgeSet& PrimGetMST(void) { return min_spanning_tree; }
#ifdef WITH_GUI
bool PrimGetStatus(void) { return status_finished; }
FibNodePtr PrimGetHeapMin(void);
#endif
class PrimException: public std::exception
{
private:
std::string msg;
public:
PrimException(const std::string& message)
{
msg = std::string("error: ") + message + "\n";
}
virtual const char* what() const throw() { return msg.c_str(); }
};
};
#endif // __PRIM_H__