- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
用散列表实现简单的英文词典
2011年4月4日星期一
一.头文件:
//文件名:Word.h
//单词类的定义
#include cstring
#include iostream.h
class Word{
friend ostream operator(ostream os, const Word obj)//重载输出函数
{
int n=strlen(obj.word);
for(int i=0; in; ++i) os obj.word[i];
return os;
}
public:
char word[25]; //用于存放单词
Word(){ for(int i=0; i25; ++i) word[i]=\0;}
bool operator==(Word r)//重载判断相等符号
{
if(strcmp(word,r.word)==0) return true;
else return false;
}
void operator=(Word r) { strcpy(word,r.word); }//重载赋值运算符
};
//文件名:openHashTable.h
//开散列表
#include cstring
#include iostream.h
template class Type
class openHashTable{
private:
struct node{//私有结点
Type data;
struct node *next;
node(){ next = NULL; }
node(Type d){ data = d; next = NULL;}
};
node **array;
int(*key)(const Type x);//关键字
static int defaultKey(const int k) { return k; }//缺省值
int size;
public:
openHashTable(int length =101 , int(* f)(const Type x) = defaultKey);
~openHashTable();
int find(Type x); //查找函数
bool insert(Type x); //插入函数
bool remove( Type x); //删除函数
void output(); //输出词典函数
};
//======================开散列表函数的实现=====================================
//构造函数的实现
template class Type
openHashTableType::openHashTable(int length, int(*f)(const Type x))
{
size = length;
array = new node *[size];
key = f;
for(int i=0; isize; ++i) array[i] = new node;
}
//析构函数的实现
template class Type
openHashTableType::~openHashTable()
{
node *p, *q;
for(int i=0; isize; ++i)
{
p = array[i];//分别析构每一个桶的相应链
do{
q = p-next;
delete p;
p = q;
}while(p!=NULL);
}
delete [] array;
}
//插入函数的实现
template class Type
bool openHashTableType::insert(Type x)
{
int pos;
node *p;
pos = key(x)%size; //计算相对应的关键字
p = array[pos]-next;
while(p!=NULL !(p-data==x)) p = p-next;
if(p==NULL)
{
p = new node(x);
p-next = array[pos]-next;
array[pos]-next = p;
return true;
}
return false;
}
//删除函数的实现
template class Type
bool openHashTableType::remove(Type x)
{
int pos;
node *p, *q;
pos = key(x)%size; //
您可能关注的文档
- B737-300飞机襟翼故障.doc
- B737-NG动力装置及APU部分(机械)课件.ppt
- B737飞机着陆标准操作指南.ppt
- BAC贴必定自粘卷材防水.doc
- BAKBONE完全安装手册.doc
- BCG汇源方案之《市场运营》.ppt
- beacon与WIFI和NFC和RFID和GPS的区别(论文资料).doc
- BEC 中级真题解析 第二辑.doc
- BEC初级口语题型解题技巧.doc
- BEC初级模拟试题九.doc
- 主题课程整理大班上.doc
- 2026人教版小学语文三年级上册期末综合试卷3套(打印版含答案解析).docx
- 2026人教版小学语文四年级下册期末综合试卷3套(打印版含答案解析).docx
- 2026人教版小学二年级上册数学期末综合试卷精选3套(含答案解析).docx
- 2026人教版小学语文四年级上册期末综合试卷3套(含答案解析).docx
- 2026人教版小学二年级下册数学期末综合试卷3套(打印版含答案解析).docx
- 2026年地理信息行业年终总结汇报PPT.pptx
- 板块四第二十一单元封建时代的欧洲和亚洲 中考历史一轮复习.pptx
- 中考历史一轮复习:板块四第二十单元古代亚、非、欧文明+课件.pptx
- 第二次工业革命和近代科学文化中考历史一轮复习.pptx
原创力文档


文档评论(0)