/
graph.h
70 lines (53 loc) · 1.32 KB
/
graph.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
#include <iostream>
using namespace std;
class ConctructionError{
private:
string mess;
public:
ConctructionError(const string& mess) : mess(mess) {
}
string const &getMess() const {
return mess;
}
};
struct ListNumberVertex {
int num;
ListNumberVertex* next;
};
template <typename T>
struct V {
char name;
T value;
// список номеров {1, 2, 4, 5, 7}
ListNumberVertex* linklist;
};
template <typename T>
struct Vertex {
bool visited;
V<T> *elem;
Vertex *next;
// обращение к списку по индексу list.each(0) ~ list[0]
Vertex* each(int i, int count);
};
template <class T>
class Graph {
int count;
Vertex<T> *VertexList = new Vertex<T>();
public:
Graph():VertexList(NULL), count(0){}
~Graph(){delete VertexList;}
// добавление элементы
void addElement(char _name, T _value);
// вывод списка вершин
void outputvertex();
// связывание вершин ребром
void edge(char at, char to);
// обход в ширину
void bfs();
// обход в глубину
void dfs();
// удобный вывод на экран
void output();
// получение значения вершины
T getValue(char name);
};