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; }
查看全文
相关阅读:
Asp.Net2.0中的缓存
webpartzone无法显示最小化和关闭按钮?
TransactionScope分布式事务和非分布式事务
JS获取GET参数的两种方法
js 文件上传下载功能
android动态设置布局LayoutInflater的使用详解
Eclipse大括号换行显示
Java强引用、 软引用、 弱引用、虚引用(转载)
Android扭曲图像(水面落叶壁纸初步实现)
win7系统自带的屏幕录制软件
原文地址:https://www.cnblogs.com/windmissing/p/2559822.html
最新文章
再读simpledb 之 SQL语句解析(2)
再读simpledb 之 元数据管理(3)
再读simpledb 之 元数据管理(2)
再读simpledb 之 SQL语句解析(1)
模拟提交有文件上传的表单
my sql 备注
ASP.NET会话(Session)保存模式
网站部署到IIS上如何进行调试
遗忘的日记
谁都来扒拉的土豆
热门文章
天晴
“致命ID”
今天的教训
初来乍到
虚拟机系列:JVM 有哪些垃圾回收算法
Asp.Net2.0常见IIS错误
.NET 2.0 新控件及其用途
最近几天很忙,也没更新~~
Asp.Net2.0默认数据库是SQL2005
(转)从Atlas到Microsoft ASP.NET AJAX
Copyright © 2011-2022 走看看