trie.h 檔案
#ifndef _trie_h
#define _trie_h
#include
#include
#include
#include
#include
using namespace std;
inline int sub_size(int level)
struct search_tree
char cchar;
bool word;
search_tree **sub_tree;
search_tree *next;
};class trie
~trie()
int add(char *str);
int prefix_in_tree(char *str);
private:
void search_tree_delete(search_tree *s_tree, int level);
void search_tree_add(search_tree *&s_tree, char *str, int level);
int prefix_in_tree(search_tree *s_tree, char *str, int level);
unsigned int hash(unsigned char cchar, int len);
search_tree *t[256];
};#endif
trie.cpp
#include "trie.h"
using namespace std;
unsigned int trie::hash(unsigned char cchar, int len)
int trie::add(char *str)
int trie::prefix_in_tree(char *str)
void trie::search_tree_add(search_tree *&s_tree, char *str, int level)
else
else
cur = s_tree;
}if (*(str + 1) == '/0')
int hash_code = hash(*(str + 1), sub_size(level + 1));
search_tree_add(cur->sub_tree[hash_code], str + 1, level + 1);
return;
}
int trie::prefix_in_tree(search_tree *s_tree, char *str, int level)
}return 0;
}void trie::search_tree_delete(search_tree *s_tree, int level)
delete s_tree;
}
樹的演算法 實現乙個Trie
insert word 傳入乙個單詞後構造字首樹的時候,將字串word轉化成字元陣列進行遍歷,要判斷單詞的當前字元是否在字首樹中,如果不在就要建立這個結點物件 如果存在就使用。將當前結點值變為孩子結點,所以要定義乙個指標currentnode初始值是this。search word 傳入乙個單詞判斷...
乙個演算法的實現
某同學幫國外某mm做的題。演算法描述 首先將兩個字串和乙個臨界值作為引數傳入函式,比如 aaaaaaaaaa bbaaababaa 2,然後在函式中依次比較兩個字串的每個字元,當不同的字元數超過指定的臨界值後,繼續比較,並將大於等於臨界值且最大數目的第乙個字串中的相同字元轉換為大寫,比如,根據以上輸...
乙個Flex MDI的實現
最近做了乙個flex的mdi實現。flex已經提供了很多優秀的元件,但是還有一些功能,甚至是常用的功能沒有提供,比如這裡的mdi。flexlib已經為我們提供了乙個相應的實現,但是使用flexlib庫需要使用它的mdicanvas和mdimanager,侵入性較高,所以,我自己實現了乙個mdi視窗。...