我使用dot / graphviz可视化一系列二叉树,其中每棵树可能指向后面的树。我遇到的问题是我想强制子节点位于其父节点的左侧或右侧。请注意,在第一个框中,来自父177的箭头位于正确的边上,但是孩子们是相反的。我怎样才能强迫孩子们站在正确的一边?
digraph ptree {
subgraph cluster_3 {
"0x2518250" [label=177,style=filled,fillcolor=black,fontcolor=white]
"0x2518250":sw -> "0x25181e0"
"0x25181e0" [label=86,style=filled,fillcolor=black,fontcolor=white]
null10 [shape=point];
"0x25181e0" -> null10;
"0x25181e0":se -> "0x251a7e0"
"0x251a7e0" [label=115,style=filled,fillcolor=red]
null11 [shape=point];
"0x251a7e0" -> null11;
null12 [shape=point];
"0x251a7e0" -> null12;
"0x2518250":se -> "0x251fc00"
"0x251fc00" [label=183,style=filled,fillcolor=black,fontcolor=white]
null13 [shape=point];
"0x251fc00" -> null13;
null14 [shape=point];
"0x251fc00" -> null14;
}
subgraph cluster_4 {
"0x251ef80" [label=177,style=filled,fillcolor=black,fontcolor=white]
"0x251ef80":sw -> "0x25181e0"
"0x251ef80":se -> "0x251ef10"
"0x251ef10" [label=183,style=filled,fillcolor=black,fontcolor=white]
null15 [shape=point];
"0x251ef10" -> null15;
"0x251ef10":se -> "0x251eea0"
"0x251eea0" [label=193,style=filled,fillcolor=red]
null16 [shape=point];
"0x251eea0" -> null16;
null17 [shape=point];
"0x251eea0" -> null17;
}
}
答案 0 :(得分:1)
导致顺序更改的原因是从右子图到86节点的边缘。您可以向左侧183节点添加另一个不可见的边缘,这将解决问题:
digraph ptree {
subgraph cluster_3 {
"0x2518250" [label=177,style=filled,fillcolor=black,fontcolor=white]
"0x2518250":sw -> "0x25181e0"
"0x25181e0" [label=86,style=filled,fillcolor=black,fontcolor=white]
null10 [shape=point];
"0x25181e0" -> null10;
"0x25181e0":se -> "0x251a7e0"
"0x251a7e0" [label=115,style=filled,fillcolor=red]
null11 [shape=point];
"0x251a7e0" -> null11;
null12 [shape=point];
"0x251a7e0" -> null12;
"0x2518250":se -> "0x251fc00"
"0x251fc00" [label=183,style=filled,fillcolor=black,fontcolor=white]
null13 [shape=point];
"0x251fc00" -> null13;
null14 [shape=point];
"0x251fc00" -> null14;
}
subgraph cluster_4 {
"0x251ef80" [label=177,style=filled,fillcolor=black,fontcolor=white]
"0x251ef80":sw -> "0x25181e0"
"0x251ef80":sw -> "0x251fc00" [style=invis] # <--- here is the change
"0x251ef80":se -> "0x251ef10"
"0x251ef10" [label=183,style=filled,fillcolor=black,fontcolor=white]
null15 [shape=point];
"0x251ef10" -> null15;
"0x251ef10":se -> "0x251eea0"
"0x251eea0" [label=193,style=filled,fillcolor=red]
null16 [shape=point];
"0x251eea0" -> null16;
null17 [shape=point];
"0x251eea0" -> null17;
}
}