Skip to content

Commit 948dc0d

Browse files
committed
update ch4
1 parent b565795 commit 948dc0d

Some content is hidden

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

43 files changed

+2226
-32
lines changed

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)
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)
77
add_executable(10_Cycle ${SOURCE_FILES})

ch4/11_EulerianCycle/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <iostream>
22
#include "../head/GraphGenerator.h"
33
#include "../head/EulerianCycle.h"
4-
#include "../head/EulerianPath.h"
54

65
// TODO: there is a bug
76
using namespace std;
@@ -12,7 +11,7 @@ using namespace std;
1211
* @param args the command-line arguments
1312
*/
1413
int main() {
15-
int V = 5;
14+
int V = 6;
1615
int E = 6;
1716

1817
// Eulerian cycle
@@ -21,7 +20,7 @@ int main() {
2120

2221
// Eulerian path
2322
Graph G2 = GraphGenerator::eulerianPath(V, E);
24-
EulerianPath::unitTest(G2, "Eulerian path");
23+
EulerianCycle::unitTest(G2, "Eulerian path");
2524

2625
// empty graph
2726
Graph G3(V);

ch4/12_EulerianPath/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <iostream>
22
#include "../head/GraphGenerator.h"
33
#include "../head/EulerianPath.h"
4-
#include "../head/EulerianCycle.h"
54

65
// TODO: there is a bug
76
using namespace std;
@@ -17,7 +16,7 @@ int main() {
1716

1817
// Eulerian cycle
1918
Graph G1 = GraphGenerator::eulerianCycle(V, E);
20-
EulerianCycle::unitTest(G1, "Eulerian cycle");
19+
EulerianPath::unitTest(G1, "Eulerian cycle");
2120

2221
// Eulerian path
2322
Graph G2 = GraphGenerator::eulerianPath(V, E);
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(16_DigraphGenerator)
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(16_DigraphGenerator ${SOURCE_FILES})

ch4/16_DigraphGenerator/main.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <iostream>
2+
#include "../head/DigraphGenerator.h"
3+
4+
using namespace std;
5+
6+
/**
7+
* Unit tests the {@code Digraph} data type.
8+
*
9+
* @param args the command-line arguments
10+
*/
11+
int main() {
12+
int V = 6;
13+
int E = 8;
14+
15+
cout << "complete graph" << endl;
16+
cout << *(DigraphGenerator::complete(V)) << endl;
17+
cout << endl;
18+
19+
cout << "simple graph" << endl;
20+
cout << *(DigraphGenerator::simple(V, E)) << endl;
21+
cout << endl;
22+
23+
cout << "path graph" << endl;
24+
cout << *(DigraphGenerator::path(V)) << endl;
25+
cout << endl;
26+
27+
cout << "cycle graph" << endl;
28+
cout << *(DigraphGenerator::cycle(V)) << endl;
29+
cout << endl;
30+
31+
cout << "Eulierian path graph" << endl;
32+
cout << *(DigraphGenerator::eulerianPath(V, E)) << endl;
33+
cout << endl;
34+
35+
cout << "Eulierian cycle graph" << endl;
36+
cout << *(DigraphGenerator::eulerianCycle(V, E)) << endl;
37+
cout << endl;
38+
39+
cout << "binary tree graph" << endl;
40+
cout << *(DigraphGenerator::binaryTree(V)) << endl;
41+
cout << endl;
42+
43+
cout << "tournament graph" << endl;
44+
cout << *(DigraphGenerator::tournament(V)) << endl;
45+
cout << endl;
46+
47+
cout << "DAG graph" << endl;
48+
cout << *(DigraphGenerator::dag(V, E)) << endl;
49+
cout << endl;
50+
51+
cout << "rooted-in DAG graph" << endl;
52+
cout << *(DigraphGenerator::rootedInDAG(V, E)) << endl;
53+
cout << endl;
54+
55+
cout << "rooted-out DAG graph" << endl;
56+
cout << *(DigraphGenerator::rootedOutDAG(V, E)) << endl;
57+
cout << endl;
58+
59+
cout << "rooted-in Tree graph" << endl;
60+
cout << *(DigraphGenerator::rootedInTree(V)) << endl;
61+
cout << endl;
62+
63+
cout << "rooted-out Tree graph" << endl;
64+
cout << *(DigraphGenerator::rootedOutTree(V)) << endl;
65+
cout << endl;
66+
}

ch4/17_DirectedDFS/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(17_DirectedDFS)
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(17_DirectedDFS ${SOURCE_FILES})

ch4/17_DirectedDFS/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/DirectedDFS.h"
3+
4+
using namespace std;
5+
6+
/**
7+
* Unit tests the {@code DirectedDFS} data type.
8+
*
9+
* @param args the command-line arguments
10+
*/
11+
int main() {
12+
string filename = "/home/ace/AceDev/C++/algorithm/ch4/data/tinyDG.txt";
13+
Digraph dg(filename);
14+
15+
vector<int> sources{2};
16+
17+
DirectedDFS dfs(dg, sources);
18+
19+
for (int v = 0; v < dg.getV(); ++v) {
20+
if (dfs.getmarked(v))
21+
cout << v << " ";
22+
}
23+
cout << endl;
24+
}
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(18_NonrecursiveDirectedDFS)
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(18_NonrecursiveDirectedDFS ${SOURCE_FILES})
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include "../head/NonrecursiveDirectedDFS.h"
3+
4+
using namespace std;
5+
6+
/**
7+
* Unit tests the {@code NonrecursiveDirectedDFS} data type.
8+
*
9+
* @param args the command-line arguments
10+
*/
11+
int main() {
12+
string filename = "/home/ace/AceDev/C++/algorithm/ch4/data/tinyDG.txt";
13+
Digraph dg(filename);
14+
15+
int source = 1;
16+
17+
NonrecursiveDirectedDFS dfs(dg, source);
18+
19+
for (int v = 0; v < dg.getV(); ++v) {
20+
if (dfs.getmarked(v))
21+
cout << v << " ";
22+
}
23+
cout << endl;
24+
}
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(19_DepthFirstDirectedPaths)
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(19_DepthFirstDirectedPaths ${SOURCE_FILES})

0 commit comments

Comments
 (0)