数据结构与程序设计(王丽苹)18searching.ppt
《数据结构与程序设计(王丽苹)18searching.ppt》由会员分享,可在线阅读,更多相关《数据结构与程序设计(王丽苹)18searching.ppt(38页珍藏版)》请在三一办公上搜索。
1、5/27/2023,数据结构与程序设计,1,数据结构与程序设计(18),王丽苹,5/27/2023,数据结构与程序设计,2,Chapter 7 SEARCHING,Information retrieval is one of the important applications of computers.We are given a list of records,where each record is associated with one piece of information,which we shall call a key(关键字).(BOOK P269 FIGURE 7.1)
2、本章讨论顺序存储列表的查找操作,链接存储在第10章讨论。,5/27/2023,数据结构与程序设计,3,Chapter 7 SEARCHING,We are given one key,called the target,and are asked to search the list to find the record(s)(if any)whose key is the same as the target.We often ask how times one key is compared with another during a search.This gives us a good
3、 measure of the total amount of work that the algorithm will do.,5/27/2023,数据结构与程序设计,4,Chapter 7 SEARCHING,The searching problem falls naturally into two cases.Internal searching(内部查找)means that all the records are kept in high-speed memory.In external searching(外部查找),most of the records are kept in
4、 disk files.We study only internal searching.,5/27/2023,数据结构与程序设计,5,Implementation of Key Class,class Key int key;public:Key(int x=0);int the_key()const;bool operator=(const Key,5/27/2023,数据结构与程序设计,6,Implementation of Key Class,Key:Key(int x)key=x;int Key:the_key()constreturn key;bool operator=(cons
5、t Key,5/27/2023,数据结构与程序设计,7,Implementation of Record Class,class Recordpublic:operator Key();/implicit conversion from Record to Key.Record(int x=0,int y=0);private:int key;int other;,5/27/2023,数据结构与程序设计,8,Implementation of Record Class,Record:Record(int x,int y)key=x;other=y;Record:operator Key()Ke
6、y tmp(key);return tmp;,5/27/2023,数据结构与程序设计,9,Test Main,void main()Key target(5);Record myrecord(5,9);if(target=myrecord)coutyesendl;else coutnoendl;调用operator Key()构造临时Key tmp,采用void operator=(const Key&x,const Key&y)操作符比较。Output:yes,5/27/2023,数据结构与程序设计,10,Implementation of Search,目录SeqSearch下例程,5/2
7、7/2023,数据结构与程序设计,11,Another Method,Recorder中的成员operator Key();主要完成从Recorder对象到Key对象的自动转换。可以用其他方法完成该功能。Use constructor to conversion from Record to Key.,5/27/2023,数据结构与程序设计,12,Implementation of Key Class,class Key int key;public:Key(int x=0);Key(const Record,5/27/2023,数据结构与程序设计,13,Implementation of K
8、ey Class,Key:Key(int x)key=x;Key:Key(const Record,5/27/2023,数据结构与程序设计,14,Implementation of Record Class,class Recordpublic:Record(int x=0,int y=0);int the_key()const;private:int key;int other;,5/27/2023,数据结构与程序设计,15,Implementation of Record Class,Record:Record(int x,int y)key=x;other=y;int Record:th
9、e_key()constreturn key;,5/27/2023,数据结构与程序设计,16,Test Main,void main()Key target(5);Record myrecord(5,9);if(target=myrecord)coutyesendl;else coutnoendl;调用Key(const Record&r)构造临时Key tmp,采用void operator=(const Key&x,const Key&y)操作符比较后,调用析构函数释放tmp。Output:yes,5/27/2023,数据结构与程序设计,17,Implementation of Searc
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 程序设计 王丽苹 18 searching

链接地址:https://www.31ppt.com/p-4980193.html