https://github.com/umbrellaleaf5/graph_cpp
Helper Graph class for C++ with CMake support
https://github.com/umbrellaleaf5/graph_cpp
cmake cpp doxygen-documentation graph
Last synced: about 2 months ago
JSON representation
Helper Graph class for C++ with CMake support
- Host: GitHub
- URL: https://github.com/umbrellaleaf5/graph_cpp
- Owner: UmbrellaLeaf5
- License: unlicense
- Created: 2024-09-23T17:58:25.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-07T10:05:44.000Z (about 1 year ago)
- Last Synced: 2025-10-14T15:33:00.399Z (6 months ago)
- Topics: cmake, cpp, doxygen-documentation, graph
- Language: C++
- Homepage: https://umbrellaleaf5.github.io/graph_cpp/
- Size: 324 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Graph_cpp: helper class for C++ with CMake support
## Description
In the second year of my MIPT DAFE/RSE education, as part of the Algorithms and Data Structures course in C++, we studied graph algorithms. For writing these, a separate Graph class was required.
At that moment, a crazy idea came to my mind: "What if I don't create a `Vertex` class, but create an `Edge` class and put it in the `private` field of the `Graph`?". And so I set out...
Over time, more and more such ideas emerged, and the lines of code grew at a doubled pace... And so this abnormal class was born, with eight static methods - pseudo-constructors, various auxiliary methods for deleting and searching for an edge or vertex, as well as templates for integer and string vertex types (more details - in the `examples` folder).
Since the project uses CMake, it is easy to integrate it into projects with the same build system - just clone the project into one folder:
```
git clone https://github.com/UmbrellaLeaf5/graph_cpp
```
or
```
git submodule add https://github.com/UmbrellaLeaf5/graph_cpp
```
and import the subdirectory:
```CMake
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/graph_cpp)
target_link_libraries(project_name PUBLIC graph_cpp)
```
## Examples
```C++
#include
#include "graph.hpp"
int main() {
std::cout << std::endl
<< "------------------------------"
" Graph from pairs "
"------------------------------"
<< std::endl
<< std::endl;
std::vector> edges_pairs = {{0, 1}, {1, 2}, {2, 0}};
auto graph = Graph::GraphNonWeighted(edges_pairs);
std::cout << "Pairs: " << edges_pairs << std::endl
<< std::endl
<< graph << std::endl
<< std::endl;
graph.PrintAdjList();
return 0;
}
```
Output:
```
------------------------------ Graph from pairs ------------------------------
Pairs: {{0; 1}; {1; 2}; {2; 0}}
Edges:
{[0->1]; [1->2]; [2->0]}
Vertices:
{0; 1; 2}
0: 1;
1: 2;
2: 0;
```