Skip to content

Commit 4598944

Browse files
author
Naudeyboo
authored
Add getting started guide (#423)
* getting started guide * Update how-to-make-a-graph.md corrected namespace * Update how-to-make-a-graph.md * Update how-to-use.md
1 parent a6b99a7 commit 4598944

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
id: how-to-make-a-graph
3+
title: 'Making a Graph'
4+
tags: ['introduction', 'how-to', 'getting started']
5+
---
6+
7+
### Requirements
8+
* C++17 or later
9+
* GCC compiler v7.3.0 OR MSVC compiler supporting C++17 or later
10+
11+
## Creating the Graph
12+
13+
At the heart of CXXGraph is the graph object. The graph object contains the nodes and edges to be worked upon.
14+
15+
Syntax for creating the graph object:
16+
17+
```
18+
Graph<int> myGraph;
19+
```
20+
21+
Whether a graph is directed or undirected is controlled by the edges added, *not the graph object itself.*
22+
23+
### Adding Nodes and Edges
24+
25+
To begin using the graph, we require nodes to create edges between. Nodes are created individually.
26+
27+
Here we create two nodes...
28+
29+
```
30+
CXXGraph::Node<int> node1("1", 1);
31+
CXXGraph::Node<int> node2("2", 2);
32+
```
33+
34+
...and then pair them together.
35+
36+
```
37+
std::pair<const CXXGraph::Node<int> *, const CXXGraph::Node<int> *> pairNode(
38+
&node1, &node2);
39+
```
40+
41+
These nodes are ready to have an edge created between them.
42+
43+
**Undirected**
44+
45+
```
46+
CXXGraph::UndirectedEdge<int> edge(1, pairNode);
47+
```
48+
49+
**Directed**
50+
51+
```
52+
CXXGraph::DirectedEdge<int> edge(1, pairNode);
53+
```
54+
55+
With the edge created, add the edge to the graph object with the `addEdge` function.
56+
57+
```
58+
myGraph.addEdge(edge);
59+
```
60+
61+
*The graph type is determined by the edges added to it.*
62+
63+
To explore the full possibilities of CXXGraph, you can find a rundown of every CXXGraph class, function, and object [here](https://rawcdn.githack.com/ZigRazor/CXXGraph/master/docs/html/annotated.html).
64+
65+
## Manipulating the Graph Object
66+
67+
CXXGraph comes packed with many useful algorithms for your graphs. To use an algorithm, simply apply it to the graph object.
68+
69+
**Traversal Algorithm**
70+
71+
The staple Depth First Search can be added to a graph like so:
72+
```
73+
auto res = myGraph.depth_first_search(node1, node2);
74+
```
75+
76+
**Advanced Algorithm**
77+
78+
Adding a more targeted algorithim is done the same way:
79+
```
80+
auto res = myGraph.dijkstra(node1, node3);
81+
```
82+
83+
For a Minimum Spanning Tree algorithim such as Kruskal's, simply ensure the right args are sent to the graph function. In this case, none, as Kruskal's traverses the entire graph.
84+
```
85+
auto mst = myGraph.kruskal();
86+
```
87+
88+
A full selection of CXXGraph's Algorithms are available [here](https://zigrazor.github.io/CXXGraph/component-explanation/regular-algorithm).
89+
90+

docusaurus/docs/getting-started/how-to-use.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,13 @@ title: 'How to Use CXXGraph'
44
tags: ['introduction', 'how to use', 'getting started']
55
---
66
### How do I put CXXGraph on my project?
7-
To use the library simply **put the header file where you need it.** It’s that easy!
7+
8+
To use CXXGraph in your project, simply put the header file `CXXGraph.hpp` where you need it, and include the following in your header:
9+
10+
```
11+
include "CXXGraph.hpp"
12+
13+
using namespace CXXGraph;
14+
```
15+
16+
It's that easy!

0 commit comments

Comments
 (0)