【发布时间】:2015-10-21 19:17:37
【问题描述】:
几乎完成了打印此尝试。但是遇到了一点小麻烦。我目前有:
void printSubtree(struct trie *subtree, char word[100], int level) {
int i;
if (subtree == NULL){
return;
}
if (subtree->wordEnd) {
word[level] =0;
printf( "%s \n ", word);
}
for (i = 0; i<26;i++) {
if (subtree->children[i]!= NULL) {
word[level] = 97 + i;
level++;
printSubtree( subtree->children[i], word, level);
}
}
}
当我这样做时,它会跳过第一个字母,所以我有另一个包含这个 sn-p 的打印第一个字母,然后调用 printSubtree 来打印对应的第一个字母的其余字母。
for (i = 0; i<26;i++) {
if (temp->children[i]!= NULL) {
arr[0] = temp->children[i]->letter;
printSubtree(temp->children[i], arr, 1);
}
}
但发生的情况是它没有正确打印出尝试。例如,如果我的 trie 中有“bro”和“brim”,则打印出“bro”然后是“brio”,而不是 brim。
提前致谢。
【问题讨论】: