Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

Embed Size (px)

Citation preview

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    1/29

    Data Structures: A Pseudocode Approachwith C   1

    Chapter 5Chapter 5

    ObjectivesUpon 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 A!

    • "rite application programs using the linear list A!

    • esign and implement different link#list structures

     List  List 

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    2/29

    Data Structures: A Pseudocode Approachwith C   2

    5-1 Basic Operations

    We begin with a discussion of the basic list operations. EachWe begin with a discussion of the basic list operations. Each

    operation is developed using before and after figures to show theoperation is developed using before and after figures to show the

    changes.changes.

    • Insertion

    • eletion

    • $etrieval

    • !raversal

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    3/29

    Data Structures: A Pseudocode Approachwith C   3

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    4/29

    Data Structures: A Pseudocode Approachwith C   4

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    5/29

    Data Structures: A Pseudocode Approachwith C   5

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    6/29

    Data Structures: A Pseudocode Approachwith C   6

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    7/29

    Data Structures: A Pseudocode Approachwith C   7

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    8/29

    Data Structures: A Pseudocode Approachwith C   8

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    9/29

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    10/29

    Data Structures: A Pseudocode Approachwith C   10

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    11/29

    Data Structures: A Pseudocode Approachwith C   11

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    12/29

    Data Structures: A Pseudocode Approachwith C   12

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    13/29

    Data Structures: A Pseudocode Approachwith C   13

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    14/29

    Data Structures: A Pseudocode Approachwith C   14

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    15/29

    Data Structures: A Pseudocode Approachwith C   15

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    16/29

    Data Structures: A Pseudocode Approachwith C   16

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    17/29

    Data Structures: A Pseudocode Approachwith C   17

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    18/29

    Data Structures: A Pseudocode Approachwith C   18

    List Search

    A list search is used to locate data in alist

     To insert data, we need to know the

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

    node to be deleted and identi its

    logical predecessor. To retrie!e data ro" a list, we need to

    search the list and fnd the data.

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    19/29

    Data Structures: A Pseudocode Approachwith C   19

    List Search

    #e "ust use a se$uential search because thereis no phsical relationship a"ong the nodes.

     The classic se$uential search returns the

    location o an ele"ent when it is ound and theaddress o the last ele"ent when it is notound.

    %ecause the list is ordered, we need to return

    the location o the ele"ent when it is ound andthe location where it should be placed when itis not ound.

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    20/29

    Data Structures: A Pseudocode Approachwith C   20

    List Search

    &i!en a target ke, the ordered listsearch atte"pts to locate there$uested node in the list.

     To search a list on a ke, we need ake feld. 'or si"ple lists the ke andthe data can be the sa"e feld.

    ( a node in the list "atches the target!alue, the search returns true) i thereare no ke "atches, it returns alse.

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    21/29

    Data Structures: A Pseudocode Approachwith C   21

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    22/29

    Data Structures: A Pseudocode Approachwith C   22

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    23/29

     Tra!ersals

    Algorith"s that tra!erse a list start atthe frst node and e*a"ine each nodein succession until the last node hasbeen processed.

     Tra!ersal logic is used b such tpeso algorith"s as changing a !alue ineach node, printing a list, su""ing a

    list, calculating the a!erage, etc. To tra!erse a list, we need a walking

    pointer that "o!es ro" node to nodeData Structures: A Pseudocode Approach

    with C   23

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    24/29

    Data Structures: A Pseudocode Approachwith C   24

    Doubl Linked List

    A doubl linked list is a linked list structurein which each node has a pointer to bothits successor and its predecessor.

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    25/29

    Data Structures: A Pseudocode Approachwith C   25

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    26/29

    ADT Structure

    Data Structures: A Pseudocode Approachwith C   26

    !here are three pieces of metadata in the head 

    structure% a count, a position pointer for

    traversals, and a rear pointer%

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    27/29

    Data Structures: A Pseudocode Approachwith C   27

    Circularl Linked List

    (n a circularl linked list, the lastnode+s link points to the frst node othe list.

    Circularl linked lists are pri"arilused in lists that allow access tonodes in the "iddle o the list

    without starting at the beginning.

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    28/29

    Data Structures: A Pseudocode Approachwith C   28

  • 8/15/2019 Documents.mx Data Structures a Pseudocode Approach With c 1 Chapter 5 Objectives Upon Completion You Will Be Able to Explain the Design Use and Operation of a Linear

    29/29

    o"ework

    Chapter -

    *ercises /01, pp. 23402-5

    Proble" /5, p. 2-/

    Data Structures: A Pseudocode Approach29