使用Graphviz 画二叉树

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
}


使用Graphviz 画二叉树_第1张图片


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="*** STRUCT STU1  ***|\
                  int id\l|\
                  char name[20]\l|\
                  char sex\l|\
                  "];
              }
    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="*** STRUCT STU2  ***|\
                  int id\l|\
                  char name[20]\l|\
                  char sex\l|\
                  "];
              }
        node_STU1:f2 -> node_STU2:f3
          }


使用Graphviz 画二叉树_第2张图片

 
  
 
  
 
  
 
  
 
 

你可能感兴趣的:(数据结构)