字典树 Tri树

本文介绍了固定存储字符的字典树,探讨了通过牺牲空间换取时间效率的可变长字典树,同时指出这种数据结构在查找操作上可能带来的性能影响。
摘要由CSDN通过智能技术生成

以下是固定存储字符的字典树。  可以以空间换时间,变为可变长的字典树,不过这样的话,查找就会费时了。


#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
			//       
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值