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; }
查看全文
相关阅读:
undefined reference to `sqrt' 问题
linux上开发minigui的配置过程
linxu select 返回值
Unix/Linux C静态库的使用
ubuntu 默认pdf阅读器乱码
文件锁使用原理及其方法
fileno函数与ftruncate函数
Linux下select函数的使用
unix linux 文件锁
iOS 基础笔试题
原文地址:https://www.cnblogs.com/windmissing/p/2559822.html
最新文章
关于Microsoft Online Services 登录应用程序
安装Office2007
安装数据服务后,要记得更新
管理域
安装Office OneNote 2007
Microsoft Office Outlook Web Access (OWA)初体验
启用Office Communications Online 以供使用
什么是BPOS
进入管理员中心
安装报表生成器Report Builder
热门文章
为Office System升级
首次以管理员用户身份登录我的公司门户
部署Office SharePoint Server 2007的步骤阶段列表
新建 SharePoint 网站集
批量建立用户帐户
安装Office InfoPath 2007
安装Office SharePoint Server 2007
用默认管理员身份登录公司门户
安装Office Project Professional 2007
如何学好C++,用好类库很重要
Copyright © 2011-2022 走看看