-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnest.cpp
More file actions
68 lines (45 loc) · 1.21 KB
/
nest.cpp
File metadata and controls
68 lines (45 loc) · 1.21 KB
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
// Hello
// "a-b, c, d-f"
// "1-2, 4-5", Node(1), Node(2) ..
// isTree()
// isBipartite()
// isConnected()
// sumOfNodes() =>
// createString() => "abcde"
// http://collabedit.com/s5ggp
Node(1) -> Node(2) -> Node(3)
template <typename T>
class Node<T>{
public:
Node<T>(T data1) { data = data1; }
private:
T data;
unordered_set<Node<T>*> neighbors;
};
template <typename T>
class Graph<T> {
public:
void insertEdge(T start, T end);
private:
bool isDirected;
unordered_set< Node<T>* > nodes;
};
enum COLOR = { WHITE, BLACK} ;
class BiPartite: public Graph {
unordered_map<Node<T>*, COLOR> myMap;
};
Node<T>* createNode(T data) {
auto iter = nodes.find(data);
if (iter != nodes.end()) return *iter;
Node<T> newtNode* = new Node<T>(data);
nodes.push_back(newNode);
return newNode;
}
template <typename T>
Graph<T>::insertEdge(T start, T end) {
Node<T>* startNode = createNode(start);
Node<T>* endNode = createNode(end);
startNode->neighbors.push_back(endNode);
if (isDirected) endNode->neighbors.push_back(startNode);
}
}