-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKruskal.h
More file actions
49 lines (49 loc) · 823 Bytes
/
Copy pathKruskal.h
File metadata and controls
49 lines (49 loc) · 823 Bytes
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
//Kruskal.h
//Algorithm 5.3 (P153-4)
//克鲁斯卡尔(Kruskal)最小花费生成树算法
#pragma once
class ClsKEdge {
public:
int u;
int v;
int cost;
ClsKEdge(){};
ClsKEdge(int au, int av, int acost) {
set(au, av, acost);
}
void set(int au, int av, int acost) {
u = au;
v = av;
cost = acost;
}
bool operator < (ClsKEdge &right)
{
return cost < right.cost;
}
bool operator > (ClsKEdge &right)
{
return cost > right.cost;
}
ClsKEdge operator = (ClsKEdge &right)
{
u = right.u;
v = right.v;
cost = right.cost;
return *this;
}
};
class ClsKNode {
public:
int vNo;
int rank;
ClsKNode *parent;
ClsKNode(){};
ClsKNode(int aVno, int arank, ClsKNode *aparent) {
set(aVno, arank, aparent);
}
void set(int aVno, int arank, ClsKNode *aparent) {
vNo = aVno;
rank = arank;
parent = aparent;
}
};