如何纵向穿越trie?

时间:2009-04-01 09:00:44

标签: c printing trie

我有一个Trie和几个修改它的功能。

typedef struct node *pnode;

typedef struct node
{
    int element;
    pnode next;//same level, other element
    pnode subtree;//next level
} node;

现在,为了调试和/或测试我的功能,我需要打印出尝试。

我递归地尝试了,但是我无法获得第一级,而不是第二级......

这样做的好方法是什么?

1 个答案:

答案 0 :(得分:2)

您必须使用队列,而不是使用堆栈(或使用重复进行模拟)。

http://en.wikipedia.org/wiki/Breadth-first_search