数据结构与程序设计(王丽苹)16-linkedl.ppt
《数据结构与程序设计(王丽苹)16-linkedl.ppt》由会员分享,可在线阅读,更多相关《数据结构与程序设计(王丽苹)16-linkedl.ppt(31页珍藏版)》请在三一办公上搜索。
1、5/27/2023,数据结构与程序设计,1,数据结构与程序设计(16),王丽苹,5/27/2023,数据结构与程序设计,2,Implementation of Linked List2,Book P225 改进的思路Keeping Suppose an application processes list entries in order or refers to the same entry several times before processing another entry.the last-used PositionRemember the last-used position i
2、n the list and,if the next operation refers to the same or a later position,start tracing through the list from this last-used position.,5/27/2023,数据结构与程序设计,3,Implementation of Linked List2,template class List public:List();List();List(const List,5/27/2023,数据结构与程序设计,4,Implementation of Linked List2,
3、protected:/Data members for the linked list/implementation now follow.int count;mutable int current_position;mutable Node*current;Node*head;/The following auxiliary function is used to/locate list positionsvoid set_position(int position)const;,5/27/2023,数据结构与程序设计,5,C+中的关键字:mutable,关键字mutable的含义:类的mu
4、table成员能够被任何成员函数修改,即使是const修饰的常量成员函数也能够对它进行修改。,5/27/2023,数据结构与程序设计,6,Implementation of Linked List2,List:List()count=0;head=NULL;current_position=0;current=NULL;,5/27/2023,数据结构与程序设计,7,Implementation of Linked List2,template void List:set_position(int position)const/*Pre:position is a valid position
5、in the List:0 next;,5/27/2023,数据结构与程序设计,8,Implementation of Linked List2,template Error_code List:insert(int position,const List_entry,5/27/2023,数据结构与程序设计,9,Implementation of Linked List2,if(position=0)head=new_node;/should be addedcurrent_position=0;current=head;elseprevious-next=new_node;/should b
6、e addedset_position(position);count+;return success;,5/27/2023,数据结构与程序设计,10,Implementation of Linked List2,position-1 position,previous,following,Position0,Position=0,following,head,new_node,new_node,5/27/2023,数据结构与程序设计,11,Implementation of Linked List2,template Error_code List:remove(int position,L
7、ist_entry,5/27/2023,数据结构与程序设计,12,Implementation of Linked List2,elsefollowing=head;head=head-next;/should be addedcurrent_position=0;current=head;x=following-entry;delete following;count-;return success;,5/27/2023,数据结构与程序设计,13,Implementation of Linked List2,position-1 position,previous,following,Pos
8、ition0,Position=0,Position=0,following,head,5/27/2023,数据结构与程序设计,14,Implementation of Linked List2,template Error_code List:retrieve(int position,List_entry,5/27/2023,数据结构与程序设计,15,Implementation of Linked List2,目录LinkList2下例程上机完成LinkList2,5/27/2023,数据结构与程序设计,16,进一步的改进,Keeping the last-used Position当插
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 程序设计 王丽苹 16 linkedl

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