Lists Chapter 4 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.

Slides:



Advertisements
Similar presentations
Lists Chapter 8 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Advertisements

Lists Chapter 4 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
Stacks Chapter 21 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Dictionary Implementations Chapter 18 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
A List Implementation That Links Data Chapter 6 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Faster Sorting Methods Chapter 12 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Creating Classes from Other Classes Chapter 2 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Completing the Linked Implementation of a List Chapter 7 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending.
List Implementations That Use Arrays Chapter 5 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Announcements.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
List Implementations That Use Arrays Chapter 5. 2 Chapter Contents Using a Fixed-Size Array to Implement the ADT List An Analogy The Java Implementation.
Iterators Chapter 8 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Queue, Deque, and Priority Queue Implementations Chapter 24 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
The Efficiency of Algorithms Chapter 9 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Trees Chapter 25 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Stack Implementations Chapter 22 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Searching Chapter 16 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Inheritance and Lists Chapter 14 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Mutable, Immutable, and Cloneable Objects Chapter 15 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Queues, Deques, and Priority Queues Chapter 23 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Data Abstraction: The Walls
An Introduction to Sorting Chapter 11 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Hashing as a Dictionary Implementation Chapter 20 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Graph Implementations Chapter 31 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Java Classes Introduction and Chapter 1 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
A Binary Search Tree Implementation Chapter 27 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Dictionaries Chapter 17 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Bags Chapter 1 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Queues, Deques, and Priority Queues Chapter 23 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All.
Data Structures and Abstractions with Java, 4e Frank Carrano
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Java Class Library: The Interface.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending.
Iterators (short version) Chapter 15 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Chapter 1 Data Abstraction: The Walls CS Data Structures Mehmet H Gunes Modified from authors’ slides.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
A Bag Implementation that Links Data Chapter 3 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions.
Balanced Search Trees (partial) Chapter 29 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall - Edited by Nadia Al-Ghreimil.
Iterator Summary Slides by Entesar Al-Mosallam adopted from Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Stacks Chapter 5 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
Lists and Sorted Lists: various implementations Slides by Nadia Al-Ghreimil adopted from Steve Armstrong LeTourneau University Longview, TX  2007, 
A Binary Search Tree Implementation Chapter 25 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions.
Recursion Chapter 10 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
1 CS162: Introduction to Computer Science II Abstract Data Types.
Sections 3.4 Formal Specification
Slides by Steve Armstrong LeTourneau University Longview, TX
Lists Chapter 4.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Hashing as a Dictionary Implementation
Iterators (short version)
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Slides by Steve Armstrong LeTourneau University Longview, TX
Slides by Steve Armstrong LeTourneau University Longview, TX
Adapted from Pearson Education, Inc.
Slides by Steve Armstrong LeTourneau University Longview, TX
Iterators (partial) Chapter 8 Slides by Nadia Al-Ghreimil
A List Implementation That Links Data
Balanced Search Trees (partial)
Stack Implementations
Copyright ©2012 by Pearson Education, Inc. All rights reserved
A List Implementation That Links Data
Copyright ©2012 by Pearson Education, Inc. All rights reserved
© 2016 Pearson Education, Ltd. All rights reserved.
A List Implementation that Uses An Array
© 2016 Pearson Education, Ltd. All rights reserved.
A List Implementation that Links Data
© 2016 Pearson Education, Ltd. All rights reserved.
Presentation transcript:

Lists Chapter 4 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Chapter Contents Specifications for the ADT List  Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending Machine Java Class Library: The Interface List

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Specifications for the ADT List 1 A list provides a way to organize data Fig. 4-1 A to-do list.

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Specifications for the ADT List Operations on lists  Add new entry – at end, or anywhere  Remove an item  Remove all items  Replace an entry  Look at any entry  Look for an entry of a specific value  Count how many entries  Check if list is empty, full  Display all the entries

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Specifications for the ADT List To specify an ADT list  Describe its data  Specify the operations ADT list must be considered in general  Not necessarily a list of strings View specifications

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Example 4 Fig. 4-2 The effect of ADT list operations on an initially empty list

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Potential Problem Operations 7 add, remove, replace, getEntry work OK when valid position given remove, replace and getEntry not meaningful on empty lists A list could become full, what happens to add ?

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Possible Solutions Assume the invalid situations will not occur Ignore the invalid situations Make reasonable assumptions, act in predictable way Return boolean value indicating success or failure of the operation Throw an exception

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Redefining Specifications 9 A first draft of an ADT specifications may ignore potential problems  Simplifies the first draft Concentrate on details after major portions of specifications written  Makes the specifications complete After writing specifications, implementations  Write Java statements to use the ADT  Checks understanding, suitability of the specifications

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Interface for ADT ListInterface 10 View source codesource code Note  Interface has no data fields, constructors  Methods must be public  Strategy for add, remove, replace, getEntry is to have them return a value  Use of return of a reference in remove and getEntry

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Using the ADT List 11 Fig. 4-3 A list of numbers that identify runners in the order in which they finish a race

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Using the ADT List 12 Consider the scoring of a running race We wish to note the order in which the runners finish We add each runner's (unique) number to the end of the list When done we display the whole list View sample programsample program

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X A List is Like a Vending Machine 17 Fig 4-4 A vending machine.

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X A List is Like a Vending Machine Observations about vending machines Can perform only tasks shown on interface Must understand the tasks Cannot see inside the machine Can use the machine even though don’t know what happens inside If inside of machine replaced with new improved version  Interface remains unchanged  Customer uses machine in same way as before

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X A List is Like a Vending Machine Observations about clients and List ADT Client can perform only operations from the ADT List Client must adhere to specifications Client cannot access data without an ADT operation Client can use the list – even though unable to access entries directly If implementation is changed, client still uses list in same way as before

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Java Class Library: The Interface List 19 The standard package contains a list interface – called List Methods provided