以下是固定存储字符的字典树。 可以以空间换时间,变为可变长的字典树,不过这样的话,查找就会费时了。
#pragma comment(linker, "/STACK:10240000,10240000")
#include<iostream>
#include <vector>
#include <memory>
#define node_size 70
#define maxlen 100
const char trie_begin_ch = 'a';
char tmp[maxlen], substring[maxlen];
int result = 0;
using namespace std;
int k;
class TriTreeNode
{
public:
TriTreeNode();
~TriTreeNode();
std::vector<std::shared_ptr<TriTreeNode>> ptr_next;
void test(bool &w, bool &l);//bool &w, bool &l
};
class TriTree
{
public:
TriTree();
bool insertEle(char *str);
void test();
private:
std::shared_ptr<TriTreeNode> root_;
};
void TriTreeNode::test(bool &w, bool &l)//
{
bool tmp_w = 1, tmp_l = 0, flag = true;
for (auto &tmp : ptr_next)
{
if (NULL != tmp)
{
tmp->test(tmp_w, tmp_l);//tmp_w, tmp_l
//