Chapter 17 Linked Lists.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Chapter 17 Linked Lists.ppt

Chapter 17 Linked Lists 17.1 Introduction to the Linked List ADT A linked list is a series of connected nodes, where each node is a data structure. A linked list can grow or shrink in size as the program runs Advantages of Linked Lists over Arrays and vectors A linked list can easily grow or shrink in size. Insertion and deletion of nodes is quicker with linked lists than with vectors. The composition of a Linked List Each node in a linked list contains one or more members that represent data. In addition to the data, each node contains a pointer, which can point to another node. The composition of a Linked List A linked list is called linked because each node in the series has a pointer that points to the next node in the list. Declarations First you must declare a data structure that will be used for the nodes. For example, the following struct could be used to create a list where each node holds a float: Declarations The next step is to declare a pointer to serve as the list head, as shown below. 17.2 Linked List Operations We will use the following class declaration (on the next slide), which is stored in FloatList.h. Appending a Node to the List To append a node to a linked list means to add the node to the end of the list. The pseudocode is shown below. The C++ code follows. Program 17-1 Stepping Through the Program The head pointer is declared as a global variable. head is automatically initialized to 0 (NULL), which indicates that the list is empty. ?The first call to appendNode passes 2.5 as the argument. In the following statements, a new node is allocated in memory, 2.5 is copied into its value member, and NULL is assigned to the nodes next pointer. Traversing the List The displayList member function traverses the list, displaying the value member of each node. The following pseudocode represents the algorithm. The C++ code for the member function follows on the next slide. Program 17-2 Program 17-2 Output Inserting a Node Using the listNode

文档评论(0)

shengyp + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档