Tag: trie

C trie试图添加撇号

我正在尝试在C中编写一个trie来读取文件并将文件中的所有单词添加到trie中,并且它运行良好,但我不能让它接受撇号: typedef struct node { bool wordBool; struct node* next[27]; // 26 letters and one space for the apostrophe } node; node* base; int numWords = 0; bool load(const char* dictionary) { FILE* dictionaryf = fopen(dictionary, “r”); // the file to read base = malloc(sizeof(node)); node variable; node *currNode = &variable; int n = 0; […]

为什么我的trie泄露数据?

我正在尝试使用trie制作拼写检查器,但是我试图添加到我的trie中的单词似乎没有被放入。泄漏在哪里? 我花了几个小时使用调试器并单步执行代码…… 主function: /** * Implements a spell-checker. */ #include #include #include #include #include “dictionary.h” #undef calculate #undef getrusage // default dictionary #define DICTIONARY “dictionaries/large” // prototype double calculate(const struct rusage *b, const struct rusage *a); int main(int argc, char *argv[]) { // check for correct number of args if (argc != 2 && argc […]

算法按字母顺序打印

我一直在忙着尝试在C中编写一个有序的树数据结构。我的程序从一个.txt一次一个地读出一个单词中的单词,然后它将每个单词存储在一个没有重复的trie中。 然后它抓取该句子中的所有其他单词并将它们存储在存储的单词的子集中。 例如,如果我们有以下句子:“贡献开源。”我的代码执行以下操作… root ab’c’defghijklmn’o’pqr’s”t’uvwxyz ‘o’ ‘p’ ‘o”o’-subtrie-> “contribute”, “open”, “source” ‘n’ ‘e’ ‘u’ ‘t’ ‘n’ ‘r’ ‘r’ ‘c’-subtrie->”contribute”, “to”, “open”, ‘i’ ‘b’ ‘u’ ‘t’ ‘e’-subtrie-> “to”, “open”, “source” 我已经成功地将单词插入到trie和子句中。 我已经对此进行了彻底的测试,因此我非常有信心一切都按照预期的方式进行。 但是,我似乎无法弄清楚algorithem按字母顺序打印trie和subtrie。 这是我正在使用的结构 typedef struct TrieNode { // number of times this string occurs in the corpus int count; // 26 TrieNode pointers, one for […]

实施TRIE数据结构

Hii,我在C中实现了一个trie …但我在insert_trie函数中遇到错误。 我无法弄清楚为什么根节点没有得到更新。 请帮我解决一下这个。 #include #include #include typedef struct { char value; int level; struct node *next; struct node *list; }node; node *trie = NULL; node *init_trie() { node *new = (node *)malloc(sizeof(node)); if(trie == NULL) { new->value = ‘$’; new->next = NULL; new->list = NULL; new->level = 0; trie = new; printf(“\n Finished initializing […]