【问题标题】:Output of tries traversal seems to be incorrect in c尝试遍历的输出在 c 中似乎不正确
【发布时间】:2014-03-06 12:59:53
【问题描述】:

这是用于打印尝试中所有单词的功能。但有时我会出错。不明白哪里出错了???请帮助我..非常感谢。

typedef int boolean;
typedef struct test_struct test_struct_t;
struct test_struct {
    boolean end;
    int freq;
    char* word;
    test_struct_t *next;
    test_struct_t *child[26];
};
typedef struct trie trie_t;
struct trie {
    struct test_struct *root;
    int count;
};
void printContent(test_struct_t *head) {
    for(int i=0;i<26;i++) {
        if(head->child[i]->w!='1') {
            if(head->child[i]->end==TRUE) {
                printf("%s (%d)\n",head->child[i]->word,head->child[i]->freq);
            }
            printContent(head->child[i]);
        }
    }
}

【问题讨论】:

  • 您遇到了什么具体错误?另外,您能否正确格式化您的代码(添加缩进、cmets、空格等)?
  • typedef int boolean;!你为什么要这么做?
  • 你能指定哪个错误?
  • 这似乎是逻辑错误我的意思是有时所有输入的单词都会通过调用此函数来显示有时不是
  • 其实我想知道如何以递归的方式去打印里面的所有单词。

标签: c data-structures recursion struct recursive-datastructures


【解决方案1】:

if(head-&gt;child[i]-&gt;w!='1'){这一行,为什么会有w

也许你可以试试这个: if( (head-&gt;child[i] != null) &amp;&amp; head-&gt;child[i]-&gt;word!='1'){

【讨论】:

  • struct test_struct { boolean end;国际频率;字符*字;字符 w; test_struct_t *下一个; test_struct_t *child[26]; };这里 w 是存储字符的地方。
猜你喜欢
  • 1970-01-01
  • 2022-01-22
  • 2023-01-14
  • 2014-07-16
  • 2019-06-14
  • 1970-01-01
  • 2014-02-24
  • 2022-12-14
  • 1970-01-01
相关资源
最近更新 更多