-
Notifications
You must be signed in to change notification settings - Fork 0
/
vertex.hpp
63 lines (52 loc) · 2.08 KB
/
vertex.hpp
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
/*
* Filename: vertex.hpp
* Description: Implements a vertex class for a graph on
* which we will apply Karger's min-cut algorithm.
*/
#ifndef VERTEX_HPP
#define VERTEX_HPP
#include <iostream>
#include <iomanip>
using namespace std;
/*
* Class name: Vertex
* Instance Variables: name (unsigned int containing vertex's label)
* rank ("Initially a set has one element and a rank of
* zero. If two sets are unioned and have the same
* rank, the resulting set's rank is one larger;
* otherwise, if two sets are unioned and have
* different ranks, the resulting set's rank is the
* larger of the two. Ranks are used instead of
* height or depth b/c path compression will change
* the trees' heights over time." - Wikipedia)
* parent (the representative of the connected component
* the vertex is in)
*
* Description: Implements a vertex class for Karger's min-cut algorithm.
* Public Methods: constructor
* Private Methods: None
*/
class Vertex {
public:
// vertex label
unsigned int name;
// rank of node
unsigned int rank;
// representative of the connected component the actor
// is in
Vertex* parent;
// Constructor that constructs a node with the given label.
Vertex(unsigned int& label) :
name(label), rank(0), parent(nullptr) {}
};
/* Overload operator<< to print a Vertex's fields to an ostream. */
inline ostream & operator <<(ostream& stm, const Vertex& v) {
stm << '[';
stm << setw(10) << &v; // Vertex address
stm << "; n:" << v.name; // Vertex name
stm << "; p:" << setw(10) << v.parent; // Vertex parent
stm << "; r:" << v.rank; // Vertex rank
stm << ']';
return stm;
}
#endif // VERTEX_HPP