gpt4 book ai didi

c - Tries 数据结构 - 打印所有值

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

我想打印我的 trie 数据结构中的所有值,以及这段代码是字典程序的一部分。

void search(struct dictionary **current) {
if((*current)->is_end==1){
printf("\n"); getchar();
}

for(int i=0; i<26; i++){
if((*current)->Children[i]!=NULL){
printf("%c",i+(int)'a');
search(&(*current)->Children[i]);
}
}
}

我想插入值(value)观。

  1. “错误”
  2. “失败”

但是当我运行该代码时,程序只显示:失败

“false”的“fa”部分没有显示,因为如果 is_end 已被标记,递归不会再次从头开始。

最佳答案

您不需要在每次到达终端节点时都从头开始递归。当您遍历 trie 并在每次 is_end 为真时打印其全部内容时,您可以只保留具有当前前缀的缓冲区。

关于c - Tries 数据结构 - 打印所有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40440543/

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