Skip to content

Instantly share code, notes, and snippets.

@jroesch
Created May 21, 2014 00:11
Show Gist options
  • Select an option

  • Save jroesch/7cf909255b8f1a6de3ad to your computer and use it in GitHub Desktop.

Select an option

Save jroesch/7cf909255b8f1a6de3ad to your computer and use it in GitHub Desktop.
Dot Printer
#include <fstream>
using namespace std;
void print2Dot(elem *elm) {
std::fstream fs;
int count = 0;
fs << "diagraph G {" << endl
fs.open("output.dot", std::fstream::out)
recursePrint2Dot(0, fs, elm);
fs << "}" << endl;
fs.close();
}
int recursePrint2Dot(int count, fstream file, elem *elm) {
auto right = recursePrint2Dot(count + 1, file, elm->smallChild),
left = recrusePrint2Dot(right, file, elm->bigChild);
file << "\t" << "node" << count << " -> " << "node" << right << endl;
file << "\t" << "node" << count << " -> " << "node" << left << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment