-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraf.cpp
68 lines (58 loc) · 780 Bytes
/
graf.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
//
// Created by user on 17.02.19.
//
#include <iostream>
class V
{
public:
const int id;
const unsigned edges;
V **v;
V(const int id_, const unsigned edges_)
: id(id_), edges(edges_), v(nullptr)
{
v = new V *[edges];
}
~V()
{
delete[] v;
}
};
void solve(V *v)
{
V *n = v;
while (true)
{
std::cout << "id:" << n->id << " ";
if (nullptr != n->v and 0 != n->edges)
{
n = n->v[0];
}
else
break;
}
}
int main_graf(int argc, char *argv[])
{
V v0(0, 1);
V v1(1, 1);
V v2(2, 1);
V v3(3, 1);
V v4(4, 1);
V v5(5, 1);
V v6(6, 1);
V v7(7, 1);
V v8(8, 1);
V v9(9, 0);
v0.v[0] = &v1;
v1.v[0] = &v2;
v2.v[0] = &v3;
v3.v[0] = &v4;
v4.v[0] = &v5;
v5.v[0] = &v6;
v6.v[0] = &v7;
v7.v[0] = &v8;
v8.v[0] = &v9;
solve(&v0);
return 0;
}