gpt4 book ai didi

c - 如何纵向遍历一个trie?

转载 作者:太空宇宙 更新时间:2023-11-04 03:08:39 25 4
gpt4 key购买 nike

我有一个 Trie以及修改它的几个函数。

typedef struct node *pnode;

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

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

我递归试过了,但是我不能得到第一级,比第二级...

有什么好的方法吗?

最佳答案

您必须使用队列而不是使用堆栈(或通过循环模拟它)。

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

关于c - 如何纵向遍历一个trie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/704675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com