zoukankan
html css js c++ java
用指针传递的字典树
#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; }
查看全文
相关阅读:
中缀表达式转换为后缀表达式
看4S员工自爆!黑啊,太黑了
解剖孩子晚上磨牙的6大原因
2D 3D IMAX 电影座位选择
蒸鸡蛋羹
0010 4S店提车注意事项
2012年北京市车船税基准税额
火车票预订 电话 和 网站
远程计算机关机方法
win7 用户信息丢失
原文地址:https://www.cnblogs.com/windmissing/p/2559822.html
最新文章
连接SDE数据库代码
Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器(第6版)
[置顶] ASP.NET环境的基本配置——VS2008+SQLEXPRESS+IIS5.1/IIS7.0
C# GEP基因化编程
C#操作内存
移动的彩虹
TexturePacker 命令行用例
用SQL语句,删除掉重复项只保留一条
C#中的访问修饰符
Sql Server快速建表
热门文章
用 java 生成 TexturePacker 的工程文件
中缀表达式转换为后缀表达式
中缀表达式转换为后缀表达式
中缀表达式转换为后缀表达式
中缀表达式转换为后缀表达式
栈和队列4 数据结构和算法26
栈和队列4 数据结构和算法26
栈和队列5|逆波兰计算器 数据结构和算法27
中缀表达式转换为后缀表达式
栈和队列5|逆波兰计算器 数据结构和算法27
Copyright © 2011-2022 走看看