graphviz 绘制红黑树

代码

digraph RedBlackTree {
    node [fontname="Arial", shape=circle, style=filled, color="#ffffff", fillcolor="#ff0000", fontsize=12, width=0.5, height=0.5];
    edge [fontname="Arial", fontsize=10, color="#333333", arrowsize=0.5];

    // 定义红黑树节点
    NULL [shape=point];
    node1 [label="1", fontcolor=white, fillcolor=black];
    node2 [label="2", fontcolor=white, fillcolor=red];
    node3 [label="3", fontcolor=white, fillcolor=black];
    node4 [label="4", fontcolor=white, fillcolor=black];
    node5 [label="5", fontcolor=white, fillcolor=black];
    node6 [label="6", fontcolor=white, fillcolor=red];
    node7 [label="7", fontcolor=white, fillcolor=black];

    // 定义红黑树的边
    NULL -> node1;
    node1 -> node2;
    node1 -> node3;
    node2 -> node4;
    node2 -> node5;
    node3 -> node6;
    node3 -> node7;
}

效果

graphviz 绘制红黑树_第1张图片

你可能感兴趣的:(#,graphviz,dot,红黑树,graphviz)