单词查找树(c++ 版)
来源:互联网 发布:好用的网络电话软件 编辑:程序博客网 时间:2024/06/05 20:27
TireST.h
#pragma once#include <memory>#include <string>class TireST{private: class Node { private: std::unique_ptr<std::unique_ptr<Node>[]> list; bool end; public: Node(const int& R = 256):list(new std::unique_ptr<Node>[R]), end(false) { for (int i = 0; i < R; ++i) list[i] = nullptr; } void put(const std::string& s,const int& pos) { if (pos == (s.length() - 1)) { if (list[s[pos]] == nullptr) list[s[pos]] = std::move(std::unique_ptr<Node>(new Node)); list[s[pos]]->end = true; return; } if (list[s[pos]] == nullptr) list[s[pos]] = std::move(std::unique_ptr<Node>(new Node)); list[s[pos]]->put(s, pos + 1); } bool find(const std::string& s, const int& pos) { if (pos >= s.length()) return false; if (pos == (s.length() - 1) && list[s[pos]]->end == true) return true; else return list[s[pos]]->find(s, pos + 1); } };private: std::unique_ptr<Node> root;public: TireST():root(new Node) { }public: void put(const std::string& s) { root->put(s, 0); } bool find(const std::string& s) { return root->find(s, 0); }};
main.cpp
#include <iostream>#include "TireST.h"#include <memory>using namespace std;int main(){ TireST ts; ts.put("Marco"); ts.put("wh"); ts.put("marco"); cout << boolalpha << ts.find("wh"); system("pause"); return 0;}
阅读全文
0 0
- 单词查找树(c++ 版)
- 三向单词查找树(c++版)
- 字典树的应用 单词意义查找-C语言实现
- 单词查找树
- 单词查找树
- 单词查找树
- 单词查找树
- 单词查找树
- 单词查找树
- 单词查找树
- 【NOI2000】单词查找树
- 单词查找树-trie
- 单词查找树
- 字符串:单词查找树
- 单词查找树
- 单词查找树
- 单词查找树
- [RQNOJ322] 单词查找树
- 微软为什么没有因《反垄断法》被美国政府强行拆分?
- DNS基础知识
- Learning R---dummy
- 面试PTC+YK
- MT 112 Status of a Request for Stop Payment of a Cheque支票止付请求状态
- 单词查找树(c++ 版)
- MT 190 Advice of Charges, Interest and Other Adjustments收费、利息和其他调整
- 实现栈和队列的不同方法
- 5.五环加权有向图-最短路径问题
- 理论篇~第二章 数据仓库的命名规范
- LeetCode 0014
- Linux查看系统配置常用命令整理
- phpcms v9 如何实现广告显示
- 数据结构小知识点