Skip to content

Commit

Permalink
Add getting started guide (#423)
Browse files Browse the repository at this point in the history
* getting started guide

* Update how-to-make-a-graph.md

corrected namespace

* Update how-to-make-a-graph.md

* Update how-to-use.md
  • Loading branch information
Naudeyboo authored May 2, 2024
1 parent a6b99a7 commit 4598944
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
90 changes: 90 additions & 0 deletions docusaurus/docs/getting-started/how-to-make-a-graph.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
id: how-to-make-a-graph
title: 'Making a Graph'
tags: ['introduction', 'how-to', 'getting started']
---

### Requirements
* C++17 or later
* GCC compiler v7.3.0 OR MSVC compiler supporting C++17 or later

## Creating the Graph

At the heart of CXXGraph is the graph object. The graph object contains the nodes and edges to be worked upon.

Syntax for creating the graph object:

```
Graph<int> myGraph;
```

Whether a graph is directed or undirected is controlled by the edges added, *not the graph object itself.*

### Adding Nodes and Edges

To begin using the graph, we require nodes to create edges between. Nodes are created individually.

Here we create two nodes...

```
CXXGraph::Node<int> node1("1", 1);
CXXGraph::Node<int> node2("2", 2);
```

...and then pair them together.

```
std::pair<const CXXGraph::Node<int> *, const CXXGraph::Node<int> *> pairNode(
&node1, &node2);
```

These nodes are ready to have an edge created between them.

**Undirected**

```
CXXGraph::UndirectedEdge<int> edge(1, pairNode);
```

**Directed**

```
CXXGraph::DirectedEdge<int> edge(1, pairNode);
```

With the edge created, add the edge to the graph object with the `addEdge` function.

```
myGraph.addEdge(edge);
```

*The graph type is determined by the edges added to it.*

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).

## Manipulating the Graph Object

CXXGraph comes packed with many useful algorithms for your graphs. To use an algorithm, simply apply it to the graph object.

**Traversal Algorithm**

The staple Depth First Search can be added to a graph like so:
```
auto res = myGraph.depth_first_search(node1, node2);
```

**Advanced Algorithm**

Adding a more targeted algorithim is done the same way:
```
auto res = myGraph.dijkstra(node1, node3);
```

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.
```
auto mst = myGraph.kruskal();
```

A full selection of CXXGraph's Algorithms are available [here](https://zigrazor.github.io/CXXGraph/component-explanation/regular-algorithm).


11 changes: 10 additions & 1 deletion docusaurus/docs/getting-started/how-to-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@ title: 'How to Use CXXGraph'
tags: ['introduction', 'how to use', 'getting started']
---
### How do I put CXXGraph on my project?
To use the library simply **put the header file where you need it.** It’s that easy!

To use CXXGraph in your project, simply put the header file `CXXGraph.hpp` where you need it, and include the following in your header:

```
include "CXXGraph.hpp"
using namespace CXXGraph;
```

It's that easy!

0 comments on commit 4598944

Please sign in to comment.