-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualizer.cpp
More file actions
27 lines (24 loc) · 816 Bytes
/
Visualizer.cpp
File metadata and controls
27 lines (24 loc) · 816 Bytes
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
#include "Visualizer.h"
#include <fstream>
#include <iostream>
#include <functional>
void Visualizer::visualize(Node* root, const std::string& filename) {
std::ofstream file(filename);
if (!file) {
std::cerr << "Failed to open file for visualization: " << filename << std::endl;
return;
}
file << "digraph G {\n";
std::function<void(Node*)> traverse = [&](Node* node) {
for (Node* child : node->children) {
file << " " << node->value << " -> " << child->value << ";\n";
traverse(child);
}
};
traverse(root);
file << "}\n";
file.close();
if (system("dot -Tpng current_graph.dot -o current_graph.png") != 0) {
std::cerr << "Failed to create PNG from DOT file." << std::endl;
}
}