Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maurodelazeri/bellmanford
Bellman–Ford Algorithm
https://github.com/maurodelazeri/bellmanford
bellmanford graph-algorithms
Last synced: 8 days ago
JSON representation
Bellman–Ford Algorithm
- Host: GitHub
- URL: https://github.com/maurodelazeri/bellmanford
- Owner: maurodelazeri
- Created: 2020-05-25T13:26:39.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-31T22:25:12.000Z (almost 4 years ago)
- Last Synced: 2024-04-17T17:12:59.512Z (7 months ago)
- Topics: bellmanford, graph-algorithms
- Language: C++
- Size: 59.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Bellman–Ford Algorithm
![](9tX9a5R.png)
```c++
#include
#include "directed_graph.h"using namespace std;
int main() {
auto graph = new Graph();
graph->add_node("A");
graph->add_node("B");
graph->add_node("C");
graph->add_node("D");
graph->add_node("E");graph->add_edge("A", "B", -1);
graph->add_edge("A", "C", 4);
graph->add_edge("B", "C", 3);
graph->add_edge("B", "D", 2);
graph->add_edge("B", "E", 2);
graph->add_edge("D", "C", 5);
graph->add_edge("D", "B", 1);
graph->add_edge("E", "D", -3);std::vector> vec;
cout << graph->bellman_ford("A",vec) << endl;
for (auto const &x : vec) {
cout << x[0] << " - " << x[1] << endl;
}graph->print();
delete graph;
return 0;
}```
```
0
0 - 0
1 - -1
2 - 2
3 - -2
4 - 1
0:
weight: -1 to: 1
weight: 4 to: 2
1:
weight: 3 to: 2
weight: 2 to: 3
weight: 2 to: 4
2:
3:
weight: 5 to: 2
weight: 1 to: 1
4:
weight: -3 to: 3Process finished with exit code 0
```