-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (46 loc) · 1.54 KB
/
main.cpp
File metadata and controls
57 lines (46 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include "DirectedGraph.h"
int main() {
DirectedGraph graph;
// Add nodes
for (char c = 'A'; c <= 'J'; ++c) {
graph.addNode(std::string(1, c));
}
// Add edges (some arbitrary connections)
graph.addEdge("A", "B");
graph.addEdge("A", "C");
graph.addEdge("B", "D");
graph.addEdge("B", "E");
graph.addEdge("C", "F");
graph.addEdge("E", "G");
graph.addEdge("F", "H");
graph.addEdge("G", "I");
graph.addEdge("H", "J");
graph.addEdge("I", "J");
graph.addEdge("J", "A");
std::cout << "Nodes: " << graph.nodeCount() << std::endl;
std::cout << "Edges: " << graph.edgeCount() << std::endl;
// Run BFS starting from A
std::cout << "\nBFS starting from node A:\n";
std::vector<std::string> bfsResult = graph.bfs("A");
for (const auto& nodeId : bfsResult) {
std::cout << nodeId << " ";
}
std::cout << std::endl;
// run dfs starting from A
std::cout << "\nDFS starting from node A:\n";
std::vector<std::string> dfsResult = graph.dfs("A");
for (const auto& nodeId : dfsResult) {
std::cout << nodeId << " ";
}
std::cout << std::endl;
// Export graph to DOT file
try {
graph.exportToDOT("graph.dot");
std::cout << "\nGraph exported to 'graph.dot'." << std::endl;
std::cout << "Use: dot -Tpng graph.dot -o graph.png to generate image." << std::endl;
} catch (const std::exception& e) {
std::cerr << "Failed to export graph: " << e.what() << std::endl;
}
return 0;
}