尝试数据结构 - 打印所有值

时间:2016-11-05 16:26:44

标签: c loops recursion data-structures trie

我想在我的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]);
        }
    }
}

我想推动价值观。

  1. “假”
  2. “失败”
  3. 但是当我运行该代码时,该程序只显示: 失败 LSE

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

1 个答案:

答案 0 :(得分:0)

每次到达终端节点时,都不需要从开始时重新启动递归。当遍历trie时,你可以使用当前前缀保留缓冲区,并在每次is_end为真时打印整个内容。

相关问题