07/06/27 18:58:52
>>371
graphviz用の入力ファイル(ただのテキスト)を作るのが楽かも
↓みたいな感じで
でも、宿題だとそれじゃ不可かな
#include <stdio.h>
typedef struct node {
char *label;
struct node *left, *right;
} node;
void tprint(node *n) {
if (!n) return;
if (n->left)
printf("%s -> %s;\n", n->label, n->left->label);
if (n->right)
printf("%s -> %s;\n", n->label, n->right->label);
tprint(n->left);
tprint(n->right);
}
int main() {
struct node tree[] = {
{ "a", &tree[1], &tree[2] }, { "b", &tree[3], &tree[4] },
{ "c", &tree[5], &tree[6] }, { "d", &tree[7], 0 },
{ "e", 0, &tree[8] }, { "f", 0, 0 }, { "g", 0, 0 },
{ "h", 0, 0 }, { "i", 0, 0 }
};
printf("digraph test {\n");
tprint(&tree[0]);
printf("}\n");
}