runxinzhi.com
首页
百度搜索
用指针传递的字典树
#include <string> using namespace std; #define NUM 26 #define TYPE 'A' class dictree { public: dictree *child[NUM]; string *value;//节点所存的数据,根据题目而使用不同的类型或数据 dictree(){memset(child,0,sizeof(child));value=NULL;} ~dictree(); bool insert(string s, string s2); string search(string s); }; //把信息s2插入到结点s处 bool dictree::insert(string s,string s2) { int len,i,j; dictree *current,*newnode; len=s.length(); if(len==0)return 0; current=this; for(i=0;i<len;i++) { if(current->child[s[i]-TYPE]!=0) current=current->child[s[i]-TYPE]; else { newnode=(dictree *)malloc(sizeof(dictree)); for(j=0;j<26;j++) newnode->child[j]=0; current->child[s[i]-TYPE]=newnode; current=newnode; } if(i == len - 1)current->value=new string(s2); } return 0; } //搜索s结点的信息 string dictree::search(string s) { int len,i; string ret = ""; dictree *current; len=s.length(); if(len==0)return ret; current=this; for(i=0;i<len;i++) { if(current->child[s[i]-TYPE]!=0) current=current->child[s[i]-TYPE]; else return ret; if(i == len - 1)ret = *current->value; } return ret; } dictree::~dictree() { if(this == NULL) return; for(int i = 0; i < 26; i++) delete this->child[i]; delete value; }
相关阅读:
axios实现跨域及突破host和referer的限制
视频测试URL地址
微信小程序 自定义导航栏 自动获取高度 写法
解决flex布局宽度超出时,子元素被压缩的问题
子组件向父组件通信与父组件向子组件通信
时间截止器
arguments
改变this指向&闭包特性
ES6扩展——箭头函数
ES6扩展——函数扩展之剩余函数
原文地址:https://www.cnblogs.com/windmissing/p/2559822.html
最新文章
20201225[java]两数求和
Q0001.intelij中添加*.sql到file types中的sql中,重启后失效
1008.函数调用
1007.操作符和优先级
ubuntu安装python3并设置默认版本
二、Excel操作与封装
一、单元测试unittest
十三、python类的继承
十二、python类和对象
十一、python模块/包/路径
热门文章
十、python异常处理
九、python文件的操作
八、python函数调用/作用域
七、python函数
六、python条件/循环
[PAT] 1001 A+B Format (20 分)Java
微信小程序中使用calc()的注意事项
vscode sftp 插件安装同步本地与服务器信息
centos7安装mongodb通过yum安装 reids
Dialog 的外层布局的 position 值为 fixed, absolute, relative 三者之一时,就会出现被蒙板遮住的情况。
Copyright © 2020-2023
润新知