- Elian iluk
- id- 214787483
- email- elian10119@gmail.com
This Graph
class having a variety of operations(overloads them) that can be performed on graphs(the operators are used on the adjacenct matrix which represent the graph itself). The graph is represented as an adjacency matrix, which is a square matrix used to represent a graph. The elements of the matrix indicate whether pairs of vertices have an edge between them and if so what is the weight of the edge, if the edge is '0' it means the vertices dont have an edge.
Graph()
- Default constructor that initializes an empty graph with zero vertices and zero edges.
-
void loadGraph(std::vector<std::vector<int>> vec1)
- Loads a graph from a given adjacency matrix
vec1
. - Checks if the input matrix is a square matrix, if not throw an error and end the program.
- Sets the number of vertices and edges based on the input matrix.
- Loads a graph from a given adjacency matrix
-
int getVertices()
- Returns the number of vertices in the graph.
-
int getEdges()
- Returns the number of edges in the graph.
-
std::vector<std::vector<int>> getGraph()
- Returns the adjacency matrix of the graph.
-
std::string printGraph()
- Returns a string representation of the graph's adjacency matrix.
-
Graph operator+(Graph& g1, Graph& g2)
- Adds two graphs by summing their adjacency matrixes.
- Returns a new graph with the new adjacency matrix.
-
Graph operator+(Graph& g1)
- Unary plus operator that returns the graph itself(there is nothing to be done, just put + on each edge).
-
Graph operator-(Graph& g1)
- Unary minus operator that negates the adjacency matrix of the graph.
-
void operator+=(Graph& g1, Graph& g2)
- Adds the adjacency matrix of
g2
tog1
and store the result ing1
.
- Adds the adjacency matrix of
-
void operator++(Graph& g1)
- Prefix increment operator that increments all non-zero elements(all edges in the matrix, a slot which equals 0 means there is no edge so we dont need to change it) of the adjacency matrix of
g1
by 1.
- Prefix increment operator that increments all non-zero elements(all edges in the matrix, a slot which equals 0 means there is no edge so we dont need to change it) of the adjacency matrix of
-
void operator++(Graph& g1, int)
- Postfix increment operator that increments all non-zero elements(all edges in the matrix, a slot which equals 0 means there is no edge so we dont need to change it) of the adjacency matrix of
g1
by 1.
- Postfix increment operator that increments all non-zero elements(all edges in the matrix, a slot which equals 0 means there is no edge so we dont need to change it) of the adjacency matrix of
-
void operator--(Graph& g1)
- Prefix decrement operator that decrements all non-zero elements(all edges in the matrix, a slot which equals 0 means there is no edge so we dont need to change it) of the adjacency matrix of
g1
by 1.
- Prefix decrement operator that decrements all non-zero elements(all edges in the matrix, a slot which equals 0 means there is no edge so we dont need to change it) of the adjacency matrix of
-
void operator--(Graph& g1, int)
- Postfix decrement operator that decrements all non-zero elements(all edges in the matrix, a slot which equals 0 means there is no edge so we dont need to change it) of the adjacency matrix of
g1
by 1.
- Postfix decrement operator that decrements all non-zero elements(all edges in the matrix, a slot which equals 0 means there is no edge so we dont need to change it) of the adjacency matrix of
-
void operator*=(Graph& g1, int num)
- Multiplies all elements of the adjacency matrix of
g1
bynum
.
- Multiplies all elements of the adjacency matrix of
-
void operator/=(Graph& g1, int num)
- Divides all elements of the adjacency matrix of
g1
bynum
. Checks for division by zero and throw an error if num==0.
- Divides all elements of the adjacency matrix of
-
Graph operator-(Graph& g1, Graph& g2)
- Subtracts the adjacency matrix of
g2
fromg1
. - Returns a new graph with the new adjacency matrix.
- Subtracts the adjacency matrix of
-
void operator-=(Graph& g1, Graph& g2)
- Subtracts the adjacency matrix of
g2
fromg1
and store it ing1
.
- Subtracts the adjacency matrix of
-
Graph operator*(Graph& g1, Graph& g2)
- Multiplies the adjacency matrix of
g1
withg2
(matrix multiplication). - Returns a new graph with the resultant adjacency matrix.
- Multiplies the adjacency matrix of
-
bool operator>(Graph& right, Graph& left)
- Compares two graphs. Returns true if
right
is "bigger" thanleft
based on:- the
left
graph is contained in full in theright
graph. - Number of edges in
right
being greater thanleft
. - The size of the adjacency matrix of
right
being larger thanleft
.
- the
- Compares two graphs. Returns true if
-
bool operator==(Graph& g1, Graph& g2)
- Checks if two graphs are equal by comparing their adjacency matrices.
-
bool operator!=(Graph& g1, Graph& g2)
- Checks if two graphs are different by comparing their adjacency matrices.
-
bool operator<(Graph& left, Graph& right)
- Compares two graphs. Returns true if
left
is less thanright
based on:- the
right
graph is contained in full in theleft
graph. - Number of edges in
left
being less thanright
. - The size of the adjacency matrix of
left
being smaller thanright
.
- the
- Compares two graphs. Returns true if
-
bool operator>=(Graph& g1, Graph& g2)
- Checks if
g1
is greater than or equal tog2
.
- Checks if
-
bool operator<=(Graph& g1, Graph& g2)
- Checks if
g1
is less than or equal tog2
.
- Checks if
-
std::ostream& operator<<(std::ostream& os, Graph& g)
- Overloads the output stream operator to print the adjacency matrix of the graph.