This repository has been archived by the owner on Jul 31, 2020. It is now read-only.
/
kruskal.h
84 lines (74 loc) · 1.47 KB
/
kruskal.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef KRUSKAL_H
#define KRUSKAL_H
#include <QPoint>
#include <QLine>
#include <utility>
#include <vector>
#include <cmath>
// int pair
typedef std::pair<int, int> iPair;
/**
* @brief The Kruskal class
* Implementation of the Kruskal's Minimum Spanning Tree
* on a Complete graph
*/
class Kruskal
{
public:
/**
* @brief Kruskal
* @param P points
*/
Kruskal(std::vector<QPoint> P);
/**
* @brief kruskalMST
* @return the MST
*/
std::vector<QLine> kruskalMST();
/**
* @brief The DisjointSets class
*/
class DisjointSets
{
public:
/**
* @brief DisjointSets
* @param n
*/
DisjointSets(int n);
/**
* @brief find
* @param u
* @return the parent of the node u
*/
int find(int u);
/**
* @brief merge by rank
* @param x
* @param y
*/
void merge(int x, int y);
private:
int *parent, *rank;
int n;
};
private:
/**
* @brief addEdge
* @param u id p1
* @param v id p2
* @param w weigth
*/
void addEdge(int u, int v, int w);
/**
* @brief distance_between_QPoint
* @param p1
* @param p2
* @return euclidean distance between the points
*/
int distance_between_QPoint(QPoint p1, QPoint p2);
int V,E;
std::vector<std::pair<int, iPair>> edges;
std::vector<QPoint> points;
};
#endif // KRUSKAL_H