-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.hpp
More file actions
78 lines (61 loc) · 2.46 KB
/
Copy pathGraph.hpp
File metadata and controls
78 lines (61 loc) · 2.46 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
69
70
71
72
73
74
75
76
77
78
// Graph.hpp
#ifndef GRAPH_HPP
#define GRAPH_HPP
#include <vector>
#include <utility>
#include <iostream>
namespace ariel {
class Graph {
private:
bool directed;
// Private helper functions
void checkSameSize(const Graph& other) const;
public:
int getEdgeCount() const;
std::vector<std::vector<int>> adjacencyMatrix;
// Constructors
Graph() = default;
Graph(const std::vector<std::vector<int>>& matrix) { loadGraph(matrix); }
// Graph functions
void loadGraph(const std::vector<std::vector<int>>& matrix);
void printGraph() const;
bool isDirected() const;
std::vector<std::pair<size_t, std::pair<size_t, int>>> getEdges() const;
std::vector<std::size_t> getNeighbors(std::size_t node) const;
int getEdgeWeight(size_t ver1, size_t ver2) const;
// Inline functions
bool getDirected() const { return this->directed; }
std::size_t getNumberOfNodes() const { return adjacencyMatrix.size(); }
bool isEdge(size_t from, size_t to) const { return adjacencyMatrix[from][to] != 0; }
std::vector<std::vector<int>> getMatrix() const { return adjacencyMatrix; }
// Arithmetic operators
Graph operator+(const Graph& other) const;
Graph& operator+=(const Graph& other);
Graph operator+() const;
Graph operator-(const Graph& other) const;
Graph& operator-=(const Graph& other);
Graph operator-() const;
Graph operator*(int scalar) const;
Graph& operator*=(int scalar); // הוספת הצהרת המפעיל *=
Graph& operator/=(int scalar); // הוספת הצהרת המפעיל /=
// Graph multiplication
Graph operator*(const Graph& other) const;
// Comparison operators
bool operator==(const Graph& other) const;
bool operator!=(const Graph& other) const;
bool operator<(const Graph& other) const;
bool operator<=(const Graph& other) const;
bool operator>(const Graph& other) const;
bool operator>=(const Graph& other) const;
// Increment and decrement operators
Graph& operator++();
Graph operator++(int);
Graph& operator--();
Graph operator--(int);
// Output operator
friend std::ostream& operator<<(std::ostream& os, const Graph& graph);
};
using StartNode = size_t;
using EndNode = size_t;
}
#endif // GRAPH_HPP