Data Structures and Abstractions with Java, 4e Frank Carrano

Slides:



Advertisements
Similar presentations
Lists Chapter 4 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
Advertisements

JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Abstract Data Types (ADTs) An ADT consists of: –a set of values, and –a set of operations on those values. Example: rational numbers –some values: 15/7,
Bag implementation Add(T item) – Enlarge bag if necessary; allocate larger array Remove(T item) – Reduce bag if necessary; allocate smaller array Iterator.
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.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Chapter 3 Collections. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 3-2 Chapter Objectives Define the concept and terminology related.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
© 2006 Pearson Addison-Wesley. All rights reserved 4-1 Chapter 4 Data Abstraction: The Walls.
Data Abstraction: The Walls
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.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Data Structures and Abstractions with Java, 4e Frank Carrano
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
An Introduction to Sorting Chapter 8 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Searching Chapter 18 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
Designing Classes Prelude © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Java Class Library: The Interface.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Chapter 13 Implementing.
Chapter 6 Stacks. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Examine stack processing Define a stack abstract.
Lists Chapter 4 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.
Bag Implementations that Use Arrays Chapter 2 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Chapter 4 Stacks and Queues © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
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, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Figure A--1 Thomas L. Floyd Digital Fundamentals, 8e Copyright ©2003 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved.
Tree Implementations Chapter 24 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java,
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Graphs Chapter 28 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
A Bag Implementation that Links Data Chapter 3 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions.
Stacks Chapter 5 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
A Binary Search Tree Implementation Chapter 25 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions.
1 CS162: Introduction to Computer Science II Abstract Data Types.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Data Abstraction: The Walls
Data Abstraction: The Walls
Chapter 1 Data Abstraction: The Walls
Lists Chapter 4.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Iterators (short version)
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Slides by Steve Armstrong LeTourneau University Longview, TX
Adapted from Pearson Education, Inc.
A List Implementation That Links Data
Lists Chapter 8.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Bag Implementations that Use Arrays
A List Implementation That Links Data
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Stack Implementations
© 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:

Data Structures and Abstractions with Java, 4e Frank Carrano Bags Chapter 1 Data Structures and Abstractions with Java, 4e Frank Carrano © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

The ADT Bag Definition Possible behaviors A finite collection of objects in no particular order Can contain duplicate items Possible behaviors Get number of items Check for empty Add, remove objects © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

FIGURE 1-1 A CRC card for a class Bag © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

Specifying a Bag Describe its data and specify in detail the methods Options that we can take when add cannot complete its task: Do nothing Leave bag unchanged, but signal client Note which methods change the object and which do not © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

FIGURE 1-2 UML notation for the class Bag © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

Design Decision What to do for unusual conditions? Assume it won’t happen Ignore invalid situations Guess at the client’s intention Return value that signals a problem Return a boolean Throw an exception © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

LISTING 1-1 A Java interface for a class of bags An Interface LISTING 1-1 A Java interface for a class of bags © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

LISTING 1-1 A Java interface for a class of bags An Interface LISTING 1-1 A Java interface for a class of bags © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

LISTING 1-1 A Java interface for a class of bags An Interface LISTING 1-1 A Java interface for a class of bags © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

LISTING 1-2 A program that maintains a bag for online shopping Using the ADT Bag LISTING 1-2 A program that maintains a bag for online shopping © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

LISTING 1-2 A program that maintains a bag for online shopping Using the ADT Bag LISTING 1-2 A program that maintains a bag for online shopping © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

LISTING 1-2 A program that maintains a bag for online shopping Using the ADT Bag LISTING 1-2 A program that maintains a bag for online shopping © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

LISTING 1-3 A class of piggy banks Example: A Piggy Bank LISTING 1-3 A class of piggy banks © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

LISTING 1-3 A class of piggy banks Example: A Piggy Bank LISTING 1-3 A class of piggy banks © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

LISTING 1-4 A demonstration of the class PiggyBank Example: A Piggy Bank LISTING 1-4 A demonstration of the class PiggyBank © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

LISTING 1-4 A demonstration of the class PiggyBank Example: A Piggy Bank LISTING 1-4 A demonstration of the class PiggyBank © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

LISTING 1-4 A demonstration of the class PiggyBank Example: A Piggy Bank LISTING 1-4 A demonstration of the class PiggyBank © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

Using ADT Like Using Vending Machine FIGURE 1-3 A vending machine © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

Observations about Vending Machines Can perform only tasks machine’s interface presents. You must understand these tasks Cannot access the inside of the machine You can use the machine even though you do not know what happens inside. Usable even with new insides. © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

Observations about ADT Bag Can perform only tasks specific to ADT Must adhere to the specifications of the operations of ADT Cannot access data inside ADT without ADT operations Use the ADT, even if don’t know how data is stored Usable even with new implementation. © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

Java Class Library: The Interface Set Listing 1-5 A Java interface for a class of sets © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

Java Class Library: The Interface Set Listing 1-5 A Java interface for a class of sets © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.

End Chapter 1 © 2015 Pearson Education, Inc., Upper Saddle River, NJ.  All rights reserved.