trie 树的简单实现
来源:互联网 发布:杭州锐智软件 编辑:程序博客网 时间:2024/06/06 13:26
namespace trie { class trieNode { public: trieNode() : nodeSize(0) { for(int i = 0; i < 26; ++i) children[i] = NULL; } ~trieNode() { for(int i = 0; i < 26; ++i) { delete children[i]; children[i] = NULL; } } public: int nodeSize; trieNode* children[26]; }; void trieInsert(string& a, trieNode* root) { if (root == NULL) return; int j = 0; while(j < a.size()) { if (root->children[a[j] - 'a'] == NULL) { root->children[a[j] - 'a'] = new trieNode(); } root = root->children[a[j] - 'a']; j++; } root->nodeSize += 1; } void trieDelete(string& a, trieNode* root) { if (root == NULL) return; int j = 0; while (j < a.size()) { if (root->children[a[j] - 'a'] == NULL) { return; } root = root->children[a[j] - 'a']; j++; } if (root) root->nodeSize -= 1; } bool trieFind(string& a, trieNode* root) { if (root == NULL) return false; int j = 0; while (j < a.size()) { int t = a[j] - 'a'; if (root->children[t] == NULL) { return false; } root = root->children[t]; j++; } return root->nodeSize != 0; }};
0 0
- Trie 树的简单实现
- trie 树的简单实现
- 简单的trie实现
- 一个Trie字典树的简单实现
- 一个简单的Trie树实现
- 一个Trie树的简单实现
- 字典树(Trie)的简单实现
- Trie树的C++简单实现
- Trie前缀树简单实现
- Trie树的实现
- Trie树的实现
- Trie树的简单实现(Java版本)
- 最简单的trie树
- Trie树的简单应用
- Trie Tree简单实现
- 初识Trie树--最简单的Trie树介绍
- Trie树数据结构的实现
- 一个Trie树的实现
- 对ViewPagerIndicator的认识
- Redis 如何处理客户端连接
- Android大图片裁剪终极解决方案(上:原理分析)
- Docker入门篇(简介、特性、安装)
- Javascript-正则简单验证身份证号
- trie 树的简单实现
- android 实现跟随手机滑动的小球
- VS2010/MFC编程入门之二十一(常用控件:编辑框Edit Control)
- StrawberryPerl的模块安装
- iOS中的HotFix方案总结详解
- 嵌入式复习13
- 设计模式<2>学到的原则
- iOS 开发中你是否遇到这些经验问题(一)
- 【Linux开发】【Qt开发】配置tslibs触摸屏库环境设置调试对应的设备挂载点