-
Notifications
You must be signed in to change notification settings - Fork 0
/
MTREE.cpp
104 lines (79 loc) · 1.31 KB
/
MTREE.cpp
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
#include <vector>
using namespace std;
struct vertex {
int v;
int e;
int prnt;
vertex* next;
vertex() {
next = NULL;
prnt = -1;
}
};
bool operator<(vertex a, vertex b ) {
return (a.e < b.e);
}
class graph {
public :
int total_weight;
vector<vertex*> G;
vector<int> parent;
vector<bool> visited;
vector< vector<int> > adj_mat;
int vertices;
void insert( int v1, int v2, int e ) {
vertex* head = G[v1];
if ( e == 0 ) {
return;
}
if ( head == NULL ) {
G[v1] = new vertex;
G[v1]->e = e;
G[v1]->v = v2;
G[v1]->prnt = v1;
return;
}
while ( head->next != NULL ) {
head = head->next;
}
head->next = new vertex;
head->next->e = e;
head->next->v = v2;
}
void print_graph() {
for ( int i = 0; i < G.size(); i++ ) {
cout << " vertex " << i << " ::: ";
print(G[i]);
}
}
void print(vertex* head) {
if ( head == NULL ) {
cout << " NULL " << endl;
return;
} else {
cout << head->v<< " -> ";
print(head->next);
}
}
graph(int v, int e ) {
vertex* tmp = NULL;
for ( int i = 0; i < v; i++ ) {
G.push_back(tmp);
}
for ( int i = 0; i < e; i++ ) {
int v1;
int v2;
int e = 1;
cin >> v1;
cin >> v2;
cin >> e;
insert(v1, v2, e);
insert(v2, v1, e);
}
}
};
int main()
{
return 0;
}