【发布时间】:2015-04-28 14:59:14
【问题描述】:
我定义了一个list_t 结构和一个list_node_t 结构如下:
typedef struct taglist_node_t {
struct taglist_node_t *pstNext;
void *pData;
} list_node_t;
typedef struct taglist_t {
list_node_t stHead;
list_node_t *pstTail;
unsigned int uiCount;
} list_t;
我决定使用graphviz绘制上面的链表,代码如下:
digraph g {
bgcolor="#BBCAF2";
label="\nSingle Linked List\n";
graph[rankdir=LR, center=true, margin=0.2, nodesep=1, ranksep=1]
edge[arrowsize=1.0, arrowhead=vee]
node[shape = Mrecord, fontname="Consolas", fontsize=20, width=1, height=1, fixedsize=false];
list[label = "<name> slist_t | <head> stHead | <tail> *pstTail | uiCount"];
node0[label = "<name> list_node_t | <next> *pstNext | *pData"];
node1[label = "<name> list_node_t | <next> *pstNext | *pData"];
head[label = "pstList"];
head -> list:name[style=bold, color=red, dir=both, arrowtail=dot];
list:head:e -> node0:name[dir=forward, arrowtail=normal];
list:tail:e -> node1:name[dir=both, arrowtail=dot];
node0:next:e -> list:head:w[dir=both, arrowtail=dot];
node1:next:e -> list:head:w[dir=both, arrowtail=dot, color=blue];
}
但是从下面的结果可以看出,蓝色线穿过了其他节点。我的问题是如何避免这种情况或将蓝线移到node1下方以避免边缘交叉?
GraphViz 结果:
【问题讨论】:
-
这与graphviz 部分无关,但您的单链表(list_node_t 类型)中有两个 元素,但它们之间没有链接。不管我怎么看,这看起来像是一个分支结构。还是我完全错过了什么???
标签: c struct linked-list graphviz