chapter 5

29
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Chapter 5 Objectives Upon completion you will be able to: Explain the design, use, and operation of a linear list Implement a linear list using a linked list structure Understand the operation of the linear list ADT Write application programs using the List List

Upload: niel

Post on 11-Feb-2016

44 views

Category:

Documents


0 download

DESCRIPTION

Chapter 5. List. Objectives . Upon completion you will be able to: Explain the design, use, and operation of a linear list Implement a linear list using a linked list structure Understand the operation of the linear list ADT Write application programs using the linear list ADT - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Chapter   5

Data Structures: A Pseudocode Approach with C 1

Chapter 5Chapter 5

Objectives

Upon completion you will be able to:

• Explain the design, use, and operation of a linear list• Implement a linear list using a linked list structure• Understand the operation of the linear list ADT• Write application programs using the linear list ADT• Design and implement different link-list structures

ListList

Page 2: Chapter   5

Data Structures: A Pseudocode Approach with C 2

5-1 Basic Operations

We begin with a discussion of the basic list operations. Each We begin with a discussion of the basic list operations. Each operation is developed using before and after figures to show the operation is developed using before and after figures to show the changes.changes.

• Insertion• Deletion• Retrieval• Traversal

Page 3: Chapter   5

Data Structures: A Pseudocode Approach with C 3

Page 4: Chapter   5

Data Structures: A Pseudocode Approach with C 4

Page 5: Chapter   5

Data Structures: A Pseudocode Approach with C 5

Page 6: Chapter   5

Data Structures: A Pseudocode Approach with C 6

Page 7: Chapter   5

Data Structures: A Pseudocode Approach with C 7

Page 8: Chapter   5

Data Structures: A Pseudocode Approach with C 8

Page 9: Chapter   5

Data Structures: A Pseudocode Approach with C 9

Page 10: Chapter   5

Data Structures: A Pseudocode Approach with C 10

Page 11: Chapter   5

Data Structures: A Pseudocode Approach with C 11

Page 12: Chapter   5

Data Structures: A Pseudocode Approach with C 12

Page 13: Chapter   5

Data Structures: A Pseudocode Approach with C 13

Page 14: Chapter   5

Data Structures: A Pseudocode Approach with C 14

Page 15: Chapter   5

Data Structures: A Pseudocode Approach with C 15

Page 16: Chapter   5

Data Structures: A Pseudocode Approach with C 16

Page 17: Chapter   5

Data Structures: A Pseudocode Approach with C 17

Page 18: Chapter   5

Data Structures: A Pseudocode Approach with C 18

List Search A list search is used to locate data in a

list To insert data, we need to know the

logical predecessor to the new data. To delete data, we need to find the

node to be deleted and identify its logical predecessor.

To retrieve data from a list, we need to search the list and find the data.

Page 19: Chapter   5

Data Structures: A Pseudocode Approach with C 19

List Search We must use a sequential search because

there is no physical relationship among the nodes.

The classic sequential search returns the location of an element when it is found and the address of the last element when it is not found.

Because the list is ordered, we need to return the location of the element when it is found and the location where it should be placed when it is not found.

Page 20: Chapter   5

Data Structures: A Pseudocode Approach with C 20

List Search Given a target key, the ordered list

search attempts to locate the requested node in the list.

To search a list on a key, we need a key field. For simple lists the key and the data can be the same field.

If a node in the list matches the target value, the search returns true; if there are no key matches, it returns false.

Page 21: Chapter   5

Data Structures: A Pseudocode Approach with C 21

Page 22: Chapter   5

Data Structures: A Pseudocode Approach with C 22

Page 23: Chapter   5

Traversals Algorithms that traverse a list start at

the first node and examine each node in succession until the last node has been processed.

Traversal logic is used by such types of algorithms as changing a value in each node, printing a list, summing a list, calculating the average, etc.

To traverse a list, we need a walking pointer that moves from node to node

Data Structures: A Pseudocode Approach with C 23

Page 24: Chapter   5

Data Structures: A Pseudocode Approach with C 24

Doubly Linked List A doubly linked list is a linked list structure

in which each node has a pointer to both its successor and its predecessor.

Page 25: Chapter   5

Data Structures: A Pseudocode Approach with C 25

Page 26: Chapter   5

ADT Structure

Data Structures: A Pseudocode Approach with C 26

There are three pieces of metadata in the head structure: a count, a position pointer for traversals, and a rear pointer:

Page 27: Chapter   5

Data Structures: A Pseudocode Approach with C 27

Circularly Linked List In a circularly linked list, the last

node’s link points to the first node of the list.

Circularly linked lists are primarily used in lists that allow access to nodes in the middle of the list without starting at the beginning.

Page 28: Chapter   5

Data Structures: A Pseudocode Approach with C 28

Page 29: Chapter   5

Homework Chapter 5 Exercises 1-3, pp. 249-250 Problem 10, p. 251

Data Structures: A Pseudocode Approach with C 29