字典树
来源:互联网 发布:风险管理矩阵 编辑:程序博客网 时间:2024/05/01 10:18
利用公共前缀减少查询时间,节省内存
静态分配,动态分配malloc次数太多,效率不行
const int maxc = 26;const int maxn = 1000010;typedef struct trie{int v;struct trie *next[maxc];}trie;trie mem[maxn];int alloc;void init(trie **root){alloc = 0;*root = create();}trie *create(){trie *p = &mem[alloc++];p->v = 0;for(int i = 0; i < maxc; ++i){p->next[i] = NULL;}return p;}void insert(trie *root, char *s){while(*s){int b = *s - 'a';++s;if(root->next[b] == NULL){root->next[b] = create();}root = root->next[b];++root->v;}}int search(trie *root, char *s){while(*s){int b = *s - 'a';++s;if(root->next[b] == NULL){return 0;}root = root->next[b];}return root->v;}
0 0
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树。。
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- android中ListView或GridView出现在adapter中的getView出现多次position为0的情况
- 哥们别逗 了,写个脚本那真不叫运维自动化! 【转载】
- 自定义一个可以随着手指拖动的按钮
- JAVA权限修饰符(public/protected/private)
- Android内存优化:ArrayMap
- 字典树
- Python2 简单下载模板
- Apple Watch 开发者套件 WatchKit 发布后,你需要知道这些
- I/O exception (java.net.SocketException) caught when processing request: Connect
- HTML的相关路径与绝对路径的问题
- 002-创建的Eclipse项目中红叹号问题解决思路
- ubuntu下常用操作
- 怎样使一个Android应用不被杀死?
- 【数据结构】静态查找之分块查找