数据结构 C++ 简单英汉字典 实验报告.doc

上传人:飞****9 文档编号:133804927 上传时间:2020-05-30 格式:DOC 页数:13 大小:166.50KB
返回 下载 相关 举报
数据结构 C++ 简单英汉字典 实验报告.doc_第1页
第1页 / 共13页
数据结构 C++ 简单英汉字典 实验报告.doc_第2页
第2页 / 共13页
数据结构 C++ 简单英汉字典 实验报告.doc_第3页
第3页 / 共13页
数据结构 C++ 简单英汉字典 实验报告.doc_第4页
第4页 / 共13页
数据结构 C++ 简单英汉字典 实验报告.doc_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《数据结构 C++ 简单英汉字典 实验报告.doc》由会员分享,可在线阅读,更多相关《数据结构 C++ 简单英汉字典 实验报告.doc(13页珍藏版)》请在金锄头文库上搜索。

1、实验报告:简单英汉字典2011-12-22实现目标及要求:1)利用散列表实现英汉字典;2) 实现散列表类,要求实现一种散列表:散列函数选取建议:将单词转成整数,再用除留余数法获得散列地址。冲突解决方法可采用开散列法。3)实现字典类,字典数据存放在内存,字典类中有两个重要数据成员:字典数组:存放字典数据的数组(或线性表)。散列表对象:作为字典数据索引的散列表。散列表元素结构包含单词和对应字典数据在字典数组中的下标,可通过散列表直接获得单词在字典数组的下标。4) 利用上面两个类实现英汉字典。5)界面要求:键盘输入单词,屏幕输出解释:界面菜单项:1.添加新词2.删除单词3.查字典查字典界面:请输入英

2、文单词:China中文翻译:中国实验环境与工具:使用Microsoft Visual Studio 2010 在Windows7 64位环境下进行实验。实验思路:分如下N步:1. 先实现链结点类的结构。2. 实现字典类的结构。3. 实现词条类的结构。4. 实现词条的散列表分类方法。5. 整合功能。主要的数据结构如下:/Hash_head.h#include#include#includeusing namespace std;const int defaultDicSize=10;const int defaultTableSize=10;class ChainNodepublic:Entry

3、 EntryLink;ChainNode *link;templateclass Dictionarypublic:Dictionary(E e);Dictionary()delete ht;bool search(string,string &);bool search(string,string &,ChainNode *&);bool insert(E);bool insert(string,string);bool remove(string);void dicPos(E e);void outputDic();private:ChainNode *ht;int dicSize;/总词

4、条数int tableSize;/每个索引容量;templateDictionary:Dictionary(E e)/计算词条数,作为字典最大长度dicSize=0;while(edicSize.chinese!=)dicSize+;/初始化字典ht=new ChainNodedicSize;for(int i=0;idicSize;i+)hti.link=NULL;hti.EntryLink=Entry();templatevoid Dictionary:dicPos(E e)int i;ChainNode *p;for(i=0;idicSize;i+)insert(ei);template

5、bool Dictionary:insert(E ent)int k;ChainNode *p1,*p2;tableSize=5;k=ent.firstLetter()%tableSize;p1=&htk;if(p1-link!=NULL)p1=p1-link;while(p1-link!=NULL)p1=p1-link;p2=new ChainNode;p2-EntryLink=ent;p2-link=NULL;p1-link=p2;return 0;templatebool Dictionary:insert(string str1,string str2)Entry *e=new Ent

6、ry (str1,str2);insert(*e);return 1;templatevoid Dictionary:outputDic()int i;ChainNode *p1;for(i=0;itableSize;i+)/cout*endl;/coutiendl;/cout*link!=NULL)p1=p1-link;p1-EntryLink.output();/cout*endl;templatebool Dictionary:remove(string str)string result;ChainNode *ptr;if(search(str,result,ptr)=1)ptr-li

7、nk=ptr-link-link;return 1;elsereturn 0; templatebool Dictionary:search(string str,string &result)ChainNode *ptr;return search(str,result,ptr);templatebool Dictionary:search(string str,string &result,ChainNode *&ptr)int k;ChainNode *p1,*p2;Entry strEnt(str);k=strEnt.firstLetter()%dicSize;p1=&htk;if(p

8、1-link!=NULL)doptr=p1;p1=p1-link;if(p1-EntryLink.word=strEnt.word)result=p1-EntryLink.chinese;return 1;while(p1-link!=NULL);return 0;elsereturn 0;/Entry_head.h#include#include#includeusing namespace std;templateclass Entrypublic:K word;K chinese;public:Entry(K,K);Entry();Entry(K);void output();int f

9、irstLetter();templateEntry:Entry(K w,K c)word=w;chinese=c;templateEntry:Entry()word=;chinese=;templateEntry:Entry(K w)word=w;chinese=;templatevoid Entry:output()cout英文:wordendl;cout中文:chineseendlendl;templateint Entry:firstLetter()char *strv = strdup (word.c_str();/stringcharreturn int(strv0);主要代码结构

10、:/Hash_main.cpp#include#include#includeEntry_head.h#includeHash_head.husing namespace std;const int deafaultSize=10+1;int main()cout*endl;cout* *endl;cout* 大猫哥 *endl;cout* Make By LJDe.de *endl;cout* E-mail:LJD *endl;cout* *endl;cout*endl;Entry edeafaultSize=Entry(eliminate,消除),Entry(accommodation ,招待设备),Entry(convince ,使确信),Entry(conscience ,良心),Entry(lantern ,灯笼),Entry(procession ,队伍),Entry(quit,离开),Entry(pudding ,布丁),Entry(reaction ,反应),Entry

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 外语文库 > 英语学习

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号