Skip to content

Commit 1c27e80

Browse files
committed
finish ch4
1 parent 9a5c9e4 commit 1c27e80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1818
-26
lines changed

README.md

Lines changed: 28 additions & 22 deletions
Large diffs are not rendered by default.

ch4/10_Cycle/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ project(10_Cycle)
33

44
set(CMAKE_CXX_STANDARD 14)
55

6-
set(SOURCE_FILES main.cpp ../head/Graph.h ../head/GraphGenerator.h ../head/DepthFirstSearch.h ../head/EulerianCycle.h ../head/EulerianPath.h ../head/SymbolGraph.h ../head/Digraph.h ../head/DirectedDFS.h ../head/NonrecursiveDirectedDFS.h ../head/DepthFirstDirectedPaths.h ../head/BreadthFirstDirectedPaths.h ../head/DirectedCycle.h ../head/DirectedCycleX.h ../head/DigraphGenerator.h ../head/DirectedEulerianCycle.h ../head/DirectedEulerianPath.h ../head/DepthFirstOrder.h ../head/Topological.h ../head/TopologicalX.h ../head/TransitiveClosure.h ../head/SymbolDigraph.h ../head/KosarajuSharirSCC.h ../head/Edge.h ../head/EdgeWeightedGraph.h ../head/LazyPrimMST.h ../head/PrimMST.h ../head/KruskalMST.h ../head/BoruvkaMST.h ../head/DirectedEdge.h ../head/EdgeWeightedDigraph.h ../head/TarjanSCC.h ../head/GabowSCC.h)
6+
set(SOURCE_FILES main.cpp ../head/Graph.h ../head/GraphGenerator.h ../head/DepthFirstSearch.h ../head/EulerianCycle.h ../head/EulerianPath.h ../head/SymbolGraph.h ../head/Digraph.h ../head/DirectedDFS.h ../head/NonrecursiveDirectedDFS.h ../head/DepthFirstDirectedPaths.h ../head/BreadthFirstDirectedPaths.h ../head/DirectedCycle.h ../head/DirectedCycleX.h ../head/DigraphGenerator.h ../head/DirectedEulerianCycle.h ../head/DirectedEulerianPath.h ../head/DepthFirstOrder.h ../head/Topological.h ../head/TopologicalX.h ../head/TransitiveClosure.h ../head/SymbolDigraph.h ../head/KosarajuSharirSCC.h ../head/Edge.h ../head/EdgeWeightedGraph.h ../head/LazyPrimMST.h ../head/PrimMST.h ../head/KruskalMST.h ../head/BoruvkaMST.h ../head/DirectedEdge.h ../head/EdgeWeightedDigraph.h ../head/TarjanSCC.h ../head/GabowSCC.h ../head/DijkstraSP.h ../head/DijkstraUndirectedSP.h ../head/DijkstraAllPairsSP.h ../head/AcyclicSP.h ../head/EdgeWeightedDirectedCycle.h ../head/AcyclicLP.h ../head/BellmanFordSP.h ../head/AdjMatrixEdgeWeightedDigraph.h ../head/FloydWarshall.h)
77
add_executable(10_Cycle ${SOURCE_FILES})

ch4/41_DijkstraSP/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(41_DijkstraSP)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
set(SOURCE_FILES main.cpp ../head/Graph.h ../head/GraphGenerator.h ../head/DepthFirstSearch.h ../head/EulerianCycle.h ../head/EulerianPath.h ../head/SymbolGraph.h)
7+
add_executable(41_DijkstraSP ${SOURCE_FILES})

ch4/41_DijkstraSP/main.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
#include "../head/DijkstraSP.h"
3+
4+
using namespace std;
5+
6+
/**
7+
* Unit tests the {@code DijkstraSP} data type.
8+
*
9+
* @param args the command-line arguments
10+
*/
11+
int main() {
12+
string file = "/home/ace/AceDev/C++/algorithm/ch4/data/tinyEWD.txt";
13+
EdgeWeightedDigraph G(file);
14+
int s = 0;
15+
16+
DijkstraSP sp(G, s);
17+
18+
for (int t = 0; t < G.V_(); ++t) {
19+
if (sp.hasPathTo(t)) {
20+
cout << s << " to " << t << " (" << sp.distTo_(t) << " ) ";
21+
for (auto e: sp.pathTo(t))
22+
cout << e << " ";
23+
cout << endl;
24+
} else
25+
cout << s << " to " << t << " no path" << endl;
26+
}
27+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(42_DijkstraUndirectedSP)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
set(SOURCE_FILES main.cpp ../head/Graph.h ../head/GraphGenerator.h ../head/DepthFirstSearch.h ../head/EulerianCycle.h ../head/EulerianPath.h ../head/SymbolGraph.h)
7+
add_executable(42_DijkstraUndirectedSP ${SOURCE_FILES})

ch4/42_DijkstraUndirectedSP/main.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
#include "../head/DijkstraUndirectedSP.h"
3+
4+
using namespace std;
5+
6+
/**
7+
* Unit tests the {@code DijkstraSP} data type.
8+
*
9+
* @param args the command-line arguments
10+
*/
11+
int main() {
12+
string file = "/home/ace/AceDev/C++/algorithm/ch4/data/tinyEWG.txt";
13+
EdgeWeightedGraph G(file);
14+
int s = 6;
15+
16+
DijkstraUndirectedSP sp(G, s);
17+
18+
for (int t = 0; t < G.V_(); ++t) {
19+
if (sp.hasPathTo(t)) {
20+
cout << s << " to " << t << " (" << fixed << setprecision(2) << sp.distTo_(t) << " ) ";
21+
for (auto e: sp.pathTo(t))
22+
cout << e << " ";
23+
cout << endl;
24+
} else
25+
cout << s << " to " << t << " no path" << endl;
26+
}
27+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(43_DijkstraAllPairsSP)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
set(SOURCE_FILES main.cpp ../head/Graph.h ../head/GraphGenerator.h ../head/DepthFirstSearch.h ../head/EulerianCycle.h ../head/EulerianPath.h ../head/SymbolGraph.h)
7+
add_executable(43_DijkstraAllPairsSP ${SOURCE_FILES})

ch4/43_DijkstraAllPairsSP/main.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include "../head/DijkstraAllPairsSP.h"
3+
4+
using namespace std;
5+
6+
/**
7+
* Unit tests the {@code DijkstraSP} data type.
8+
*
9+
* @param args the command-line arguments
10+
*/
11+
int main() {
12+
string file = "/home/ace/AceDev/C++/algorithm/ch4/data/tinyEWD.txt";
13+
EdgeWeightedDigraph G(file);
14+
15+
DijkstraAllPairsSP dsp(G);
16+
17+
int s = 1, t = 2;
18+
if (dsp.hasPath(s, t)) {
19+
cout << s << " to " << t << " : ";
20+
for (auto e: dsp.path(s, t))
21+
cout << e << " ";
22+
cout << endl;
23+
}
24+
}

ch4/44_AcyclicSP/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(44_AcyclicSP)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
set(SOURCE_FILES main.cpp ../head/Graph.h ../head/GraphGenerator.h ../head/DepthFirstSearch.h ../head/EulerianCycle.h ../head/EulerianPath.h ../head/SymbolGraph.h)
7+
add_executable(44_AcyclicSP ${SOURCE_FILES})

ch4/44_AcyclicSP/main.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
#include "../head/AcyclicSP.h"
3+
4+
using namespace std;
5+
6+
/**
7+
* Unit tests the {@code AcyclicSP} data type.
8+
*
9+
* @param args the command-line arguments
10+
*/
11+
int main() {
12+
string file = "/home/ace/AceDev/C++/algorithm/ch4/data/tinyEWDAG.txt";
13+
EdgeWeightedDigraph G(file);
14+
15+
int s = 5;
16+
AcyclicSP asp(G, s);
17+
18+
for (int v = 0; v < G.V_(); ++v) {
19+
if (asp.hasPathTo(v)) {
20+
cout << s << " to " << v << " (" << asp.distTo_(v) << ") ";
21+
for (auto e: asp.pathTo(v))
22+
cout << e << " ";
23+
cout << endl;
24+
} else
25+
cout << s << " to " << v << " no path" << endl;
26+
}
27+
}

0 commit comments

Comments
 (0)