Copyright ©2012 by Pearson Education, Inc. All rights reserved

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.
The Efficiency of Algorithms Chapter 4 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
A Bag Implementation that Links Data Chapter 3 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
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.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Queue, Deque, and Priority Queue Implementations Chapter 11 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Queues, Deques and Priority Queues Chapter 10 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
A Binary Search Tree Implementation Chapter 25 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Bag Implementations that Use Arrays Chapter 2 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
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.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Data Structures and Abstractions with Java, 4e Frank Carrano
Abstract Data Types Chapter 1. Today n Data Types & Abstract Data Types n Designing Systems and ADTs use casesuse cases class-responsibility-collaboration.
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 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 2 Collections. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Define the concept and terminology related.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
Stack Implementations Chapter 6 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
A Heap Implementation Chapter 26 Copyright ©2012 by Pearson Education, Inc. 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.
Array-Based Implementations Chapter 3 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 18 List ADT Animated Version.
Stacks Chapter 5 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
1 CS162: Introduction to Computer Science II Abstract Data Types.
Data Abstraction: The Walls
Queues Chapter 8 (continued)
Data Abstraction: The Walls
Chapter 1 Data Abstraction: The Walls
Lists Chapter 4.
Bag Implementations that Use Arrays
A Bag Implementation that Links Data
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Queues, Deques and Priority Queues
Queue, Deque, and Priority Queue Implementations
A Bag Implementation that Links Data
Queues, Deques and Priority Queues
Stacks Chapter 5 Adapted from Pearson Education, Inc.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Hashing as a Dictionary Implementation
List Implementations Chapter 9
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Slides by Steve Armstrong LeTourneau University Longview, TX
Adapted from Pearson Education, Inc.
Dynamic Data Structures and Generics
Array-Based Implementations
List Implementations that Use Arrays
A List Implementation That Links Data
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Array-Based Implementations
Lists Chapter 8.
Bag Implementations that Use Arrays
A Binary Search Tree Implementation
Java Generics & Iterators
A List Implementation That Links Data
Copyright ©2012 by Pearson Education, Inc. All rights reserved
List Implementations that Use Arrays
© 2016 Pearson Education, Ltd. All rights reserved.
© 2016 Pearson Education, Ltd. All rights reserved.
A List Implementation that Links Data
© 2016 Pearson Education, Ltd. All rights reserved.
Presentation transcript:

Copyright ©2012 by Pearson Education, Inc. All rights reserved Bags Chapter 1 Copyright ©2012 by Pearson Education, Inc. All rights reserved

Copyright ©2012 by Pearson Education, Inc. All rights reserved Contents The Bag A Bag’s Behaviors Specifying a Bag An Interface Using the ADT Bag Using an ADT Is Like Using a Vending Machine Copyright ©2012 by Pearson Education, Inc. All rights reserved

Copyright ©2012 by Pearson Education, Inc. All rights reserved Objectives Describe the concept of abstract data type (ADT) Describe ADT bag Use ADT bag in Java program Copyright ©2012 by Pearson Education, Inc. All rights reserved

Copyright ©2012 by Pearson Education, Inc. All rights reserved Definition: Bag A finite collection of objects In no particular order May contain duplicate items Copyright ©2012 by Pearson Education, Inc. All rights reserved

Copyright ©2012 by Pearson Education, Inc. All rights reserved Behaviors Determine how many objects in bag Full? Empty? Add, remove objects Count duplicates Test for specific object View all objects Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 1-1 A CRC card for a class Bag

Copyright ©2012 by Pearson Education, Inc. All rights reserved Specifying a Bag Describe data Specify methods for bag’s behaviors Name methods Choose parameters Decide return types Write comments Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 1-2 UML notation for the class Bag

Copyright ©2012 by Pearson Education, Inc. All rights reserved Design Decisions What should the method add do when it cannot add a new entry? Nothing? Leave bag unchanged, signal client of condition? Copyright ©2012 by Pearson Education, Inc. All rights reserved

Copyright ©2012 by Pearson Education, Inc. All rights reserved Design Decisions What should happen when an unusual condition occurs? Assume invalid never happens? Ignore invalid event? Guess at client’s intention? Return flag value? Return boolean value – success/failure? Throw exception? Copyright ©2012 by Pearson Education, Inc. All rights reserved

Interface Write Java headers Organize into interface Note items in bag are of same type Generic type <T> View Listing 1-1 Note: Code listing files must be in same folder as PowerPoint files for links to work Copyright ©2012 by Pearson Education, Inc. All rights reserved

Copyright ©2012 by Pearson Education, Inc. All rights reserved Using ADT Bag Implementation done from specifications User needs know what ADT does, not how Type of object in bag specified by program using the ADT Example of Bag for online shopping Listing 1-2 Copyright ©2012 by Pearson Education, Inc. All rights reserved

Copyright ©2012 by Pearson Education, Inc. All rights reserved Using ADT Bag Example of Bag for class of piggy banks Listing 1-3 Demonstration of class PiggyBank Listing 1-4 Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 1-3 A Vending Machine

Vending Machine Like An ADT Perform only available tasks User must understand the tasks Cannot access inside of mechanism Usable without knowing inside implementation New inside implementation unknown to users Copyright ©2012 by Pearson Education, Inc. All rights reserved

Copyright ©2012 by Pearson Education, Inc. All rights reserved Class Library The interface Set public boolean add(T newEntry) public boolean remove(Object anEntry) public void clear() public boolean contains(Object anEntry) public boolean isEmpty() public int size() public Object[] toArray() Copyright ©2012 by Pearson Education, Inc. All rights reserved

Copyright ©2012 by Pearson Education, Inc. All rights reserved End Chapter 1 Copyright ©2012 by Pearson Education, Inc. All rights reserved