資源簡介
用C語言實現(xiàn)的字典樹算法,用C語言實現(xiàn)的字典樹算法。
代碼片段和文件信息
#include
#include?
????????????????????//字典樹或者鍵樹?
#define?KIND?26;????//字母種類?
typedef?struct?node{
????int?count;//記錄遍歷到該節(jié)點形成的字符串出現(xiàn)的次數(shù)?
????struct?node*?next[KIND];?//指向兒子節(jié)點?
}trie;
int?init_trie(trie*&?T)
{
????int?i?=?0;
????T->count?=?1;
????for(;?i?????????T->next[i]?=?NULL;
}?
int?insert(trie*&?root?char*?word)?//插入?
{
????trie*?temp;
????int?i?=?0?branch?=?0;
????
????if(root?==?NULL)
????{
????????root?=?(trie*)malloc(sizeof(trie));
????????init_trie(root);
????}?
????
????temp?=?root;
????while(word[i]?!=?‘\0‘)
????{
????????branch?=?word[i]?-?‘a(chǎn)‘;
????????if(tem
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1336??2009-09-22?19:49??trie.cpp
-----------?---------??----------?-----??----
?????????????????1336????????????????????1
評論
共有 條評論