From b11d99ca9423d0cdd13ba08eff9313b1a4f06777 Mon Sep 17 00:00:00 2001 From: Abdurrezzak Efe Date: Thu, 16 Nov 2017 13:21:26 +0200 Subject: [PATCH] Add files via upload --- 24.BellmanFord.cpp | 104 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 24.BellmanFord.cpp diff --git a/24.BellmanFord.cpp b/24.BellmanFord.cpp new file mode 100644 index 0000000..1fad0fb --- /dev/null +++ b/24.BellmanFord.cpp @@ -0,0 +1,104 @@ +/* + * This program constructs a graph from user inputs and + * find a single source shortest path using + * Ballman-Ford algorithm + * + * Coded by: Abdurrezak Efe + * + * */ + +#include +#include +using namespace std; +typedef pair< int , int> edge; + +//constructing the graph +class Graph{ + +public: + + vector > edges; + int v; + int e; + + Graph(int v, int e) + { + //edges.resize(e); + this->v = v; + this->e = e; + } + + void add_edge(int x, int y, int w) + { + edge ee = {x,y}; + pair newedge= {w, ee}; + edges.push_back(newedge); + } + +}; + + +bool bellman_ford(Graph g) +{ + //initializing arrays + int distance[g.v]; + int previous[g.v]; + + for(int i=0;i> v >> e; + + Graph g(v,e); + + int x,y,w; + for(int i=0;i> x >> y >> w; + g.add_edge(x,y,w); + } + + bellman_ford(g); +} \ No newline at end of file