数据结构与程序设计(王丽苹)15linkedl.ppt
《数据结构与程序设计(王丽苹)15linkedl.ppt》由会员分享,可在线阅读,更多相关《数据结构与程序设计(王丽苹)15linkedl.ppt(36页珍藏版)》请在三一办公上搜索。
1、5/27/2023,数据结构与程序设计,1,数据结构与程序设计(15),王丽苹,5/27/2023,数据结构与程序设计,2,Linked List Implementation,本章主要讨论链表的实现。即用链接存储形式来实现列表。,5/27/2023,数据结构与程序设计,3,Linked List Implementation,链表中节点的类型定义:template struct Node/data membersNode_entry entry;Node*next;/constructorsNode();Node(Node_entry item,Node*link=NULL);,5/27/2
2、023,数据结构与程序设计,4,Actions on a Linked List,Book P222 Figure 6.1,5/27/2023,数据结构与程序设计,5,Actions on a Linked List,5/27/2023,数据结构与程序设计,6,Implementation of Linked List,列表的链接实现方式,请参考:目录LinkList下例程,5/27/2023,数据结构与程序设计,7,Implementation of Linked List,/结构体类型Node的定义。template struct Node/data membersNode_entry e
3、ntry;Node*next;/constructorsNode();Node(Node_entry item,Node*add_on=NULL);,5/27/2023,数据结构与程序设计,8,Implementation of Linked List,/构造函数的实现templateNode:Node()next=NULL;templateNode:Node(Node_entry item,Node*add_on)entry=item;next=add_on;,5/27/2023,数据结构与程序设计,9,Implementation of Linked List,enum Error_cod
4、eunderflow,overflow,range_error,success;template class List public:List();List();List(const List,5/27/2023,数据结构与程序设计,10,Implementation of Linked List,template List:List()count=0;head=NULL;,5/27/2023,数据结构与程序设计,11,Implementation of Linked List,template Node*List:set_position(int position)const/*Pre:po
5、sition is a valid position in the List;0*q=head;/引入临时的指针q/通过q来周游链表for(int i=0;i next;return q;,5/27/2023,数据结构与程序设计,12,Implementation of Linked List,Insert操作,5/27/2023,数据结构与程序设计,13,Implementation of Linked List,template Error_code List:insert(int position,const List_entry,5/27/2023,数据结构与程序设计,14,Imple
6、mentation of Linked List,/产生新的节点空间。new_node=new Node(x,following);if(new_node=NULL)return overflow;/将新产生的节点加入到链表中。if(position=0)head=new_node;elseprevious-next=new_node;count+;return success;,5/27/2023,数据结构与程序设计,15,Implementation of Linked Insert的两种情况:,position-1 position,previous,following,Position
7、0,Position=0,following,head,new_node,new_node,5/27/2023,数据结构与程序设计,16,Implementation of Linked List,template Error_code List:remove(int position,List_entry,5/27/2023,数据结构与程序设计,17,Implementation of Linked Listremove的两种情况:,position-1 position,previous,following,Position0,Position=0,Position=0,following
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 程序设计 王丽苹 15 linkedl
链接地址:https://www.31ppt.com/p-4980194.html