使用Graphviz 画二叉树

来源:互联网 发布:正大华日软件 编辑:程序博客网 时间:2024/06/05 14:30

1.安装graphviz

sudo apt-get install graphviz

2.编写.dot文件

vi test.dot

digraph abc{    a;      b;      c;      d;      e;      a->b [label=left]    a->e [label=abc]    b->d    e->d}


3.编译生成图片
dot -Tpng test.dot -o test.png
eog  test.png


4.改进后代码,可以设置节点颜色

digraph abc{    a [color=red style=filled fontcolor=white];    b [color=black style=filled fontcolor=white];    c [color=black];    d;      e;      a->b [label=left]    a->e [label=abc]    b->d    e->d}




5.画结构体,利用emacs下的graphivz-dot-mode,参考http://emacser.com/emacs_graphviz_ds.htm

C-c c   编译

C-c p  另开buffuer显示图片

// $Id: (>>FILE<<), (>>DATE<<)digraph Name {    node [shape=record fontsize=12 fontname=Courier style=filled];    edge[color=blue];    rankdir=LR;    // XXX: place to put subgraph    subgraph cluster_STU12  {        node [shape=record fontsize=12 fontname=Courier style=filled];        color = lightgray;        style=filled;        label = "Struct STU1 ";        edge[color="#2e3436"];        node_STU1 [shape=record label="<f0>*** STRUCT STU1  ***|\                  <f2>int id\l|\                  <f3>char name[20]\l|\                  <f4>char sex\l|<f999>\                  "];              }    subgraph cluster_STU34  {        node [shape=record fontsize=12 fontname=Courier style=filled];        color = lightgray;        style=filled;        label = "Struct STU2 ";        edge[color="#2e3436"];        node_STU2 [shape=record label="<f0>*** STRUCT STU2  ***|\                  <f2>int id\l|\                  <f3>char name[20]\l|\                  <f4>char sex\l|<f999>\                  "];              }        node_STU1:f2 -> node_STU2:f3          }




                                             
0 0
原创粉丝点击