background image
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include "datatype.h"
/**
* trie 树节点
*/
typedef struct TrieNode
{
wchar_t character;
// 字符
bool isword;
// 是否是单词节点
struct TrieNode *children;
// 子节点数组
long childrenCount;
// 字节点数量
} TrieNode;
/**
* 初始化 trie 树,建立词库搜索树
* @param dic
词库字典文件
*/
TrieNode* trie_init(FILE* dic);
/**
* 打印 trie 树
* @param root
字典
*/
void trie_print(TrieNode* root);
/**
* 判断字符串是不是单词
* @param root
字典
* @param word
字符串
*/
bool trie_is_word(TrieNode* root, wchar_t *word);
#endif /* TRIE_H_ */
限于篇幅,剩下的实现代码,请有兴趣的读者,自行实现了。
测试函数为
int main()