Skip to content

Commit 02d8394

Browse files
authored
modified README to correctly reflect using example with corrections to the code (#599)
Co-authored-by: Skandan C Y <skandanyal@users.noreply.github.com>
1 parent 4a23155 commit 02d8394

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,23 @@ For self-compiled installations using CMake, execute the following from the comm
140140

141141
## How to use
142142

143-
To use the library **simply include the header file `CXXGraph.hpp`**, (make sure to add the [include folder](https://github.com/ZigRazor/CXXGraph/tree/master/include) to your compiler's inlcude path).
143+
[//]: # (To use the library **simply include the header file `CXXGraph.hpp`**, &#40;make sure to add the [include folder]&#40;https://github.com/ZigRazor/CXXGraph/tree/master/include&#41; to your compiler's inlcude path&#41;.)
144+
To use the library, simply include the `CXXGraph/CXXGraph.hpp` file at the top of your file.
145+
146+
While compiling the file, include the two include paths mentioned in the `To compile and run the program` section in the command.
144147

145148
CXXGraph revolves around the graph object which contains nodes and edges. This object can then be manipulated with a wide variety of algorithms. Please see the [examples section](#examples), [examples folder](https://github.com/ZigRazor/CXXGraph/tree/master/examples) and [website](https://zigrazor.github.io/CXXGraph/) for more information
146149

147150
## Examples
148151

149-
In this example, the shortest path between nodeA and nodeC is obtained using Dijkstra's algorithm.
152+
In this example file `example.cpp`, the shortest path between nodeA and nodeC is obtained using Dijkstra's algorithm.
153+
```bash
154+
$ mkdir folder
155+
$ cd folder
156+
$ touch example.cpp
157+
```
150158

159+
Paste the below code into example.cpp
151160
```cpp
152161
#include <iostream>
153162
#include "CXXGraph/CXXGraph.hpp"
@@ -162,9 +171,9 @@ int main(){
162171
CXXGraph::UndirectedWeightedEdge<int> edge3("3", nodeA, nodeC, 6);
163172

164173
CXXGraph::T_EdgeSet<int> edgeSet;
165-
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge1));
166-
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge2));
167-
edgeSet.insert(make_shared<CXXGraph::UndirectedWeightedEdge<int>>(edge3));
174+
edgeSet.insert(std::make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge1));
175+
edgeSet.insert(std::make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge2));
176+
edgeSet.insert(std::make_shared<CXXGraph::UndirectedWeightedEdge<int>>(edge3));
168177

169178
CXXGraph::Graph<int> graph(edgeSet);
170179
CXXGraph::DijkstraResult res = graph.dijkstra(nodeA, nodeC);
@@ -175,6 +184,21 @@ int main(){
175184
}
176185
```
177186

187+
### To compile and run the program
188+
189+
Use the following command to compile the program:
190+
``` bash
191+
# while the path points to /folder/
192+
193+
$ g++ <path_to/folder/example.cpp> -I <path_to/CXXGraph/include> \
194+
-I <path_to/CXXGraph/build/include> -std=c++17
195+
```
196+
This will generate an executable binary `a.out`.
197+
Use the following command to run the compiled binary:
198+
```
199+
./a.out
200+
```
201+
178202
See more examples in the [examples folder](https://github.com/ZigRazor/CXXGraph/tree/master/examples).
179203

180204
## Unit-Test Execution

0 commit comments

Comments
 (0)