-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.h
64 lines (56 loc) · 1.73 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
#ifndef _GRAPH_H_
#define _GRAPH_H_
#include <iostream>
#include <cstring>
#define GRAPH_SIZE 3
using namespace std;
template <class T>
class Graph
{
public:
enum graph_error {
EINVARG = 1,
EEXISTS,
ENEXISTS
};
Graph();
Graph (int size);
Graph (const Graph<T> &g1);
~Graph();
int edge (int from, int to, int cost, bool true_if_add, bool true_if_replace_or_remove);
void add_edge (int from, int to, int cost);
void add_or_replace_edge (int from, int to, int cost);
void remove_edge (int from, int to);
int edge_cost (int from, int to);
T value (int vertex_key, T recieved_value, bool true_if_add, bool true_if_replace_or_remove);
void add_value (int vertex_key, T recieved_value);
void add_or_replace_value (int vertex_key, T recieved_value);
void remove_value (int vertex_key);
T get_value (int vertex_key);
Graph<T>& operator=(const Graph<T> &g1);
friend ostream &operator<<(ostream &output, const Graph &g) {
if (g.g_size == 0) {
output << "No vertices in graph" << endl;
return output;
}
output << "Number of vertices - " << g.g_size << "\n";
for (int i = 0; i < g.g_size; ++i)
output << "\t" << i;
output << "\n";
for (int i = 0; i < g.g_size; ++i) {
output << i << "\t";
for (int j = 0; j < g.g_size; ++j)
output << g.g_edges[i][j] << "\t";
output << "\n";
}
for (int i = 0; i < g.g_size; ++i)
output << i << "\t" << g.g_used_values[i] << "\t\t" <<g.g_values[i] << endl;
return output;
}
private:
int **g_edges;
T *g_values;
int g_size;
bool *g_used_values;
};
#endif