Data Structures and Abstractions with Java ™
5th Edition
Chapter 1
Bags
Copyright © 2019, 2015, 2012 Pearson Education, Inc. All Rights Reserved
,What Is an Iterator?
• An object that traverses a collection of data
• During iteration, each data item is considered once
– Possible to modify item as accessed
• Should implement as a distinct class that interacts with
the ADT
Copyright © 2019, 2015, 2012 Pearson Education, Inc. All Rights Reserved
, The ADT Bag
• Definition
– 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
Copyright © 2019, 2015, 2012 Pearson Education, Inc. All Rights Reserved
5th Edition
Chapter 1
Bags
Copyright © 2019, 2015, 2012 Pearson Education, Inc. All Rights Reserved
,What Is an Iterator?
• An object that traverses a collection of data
• During iteration, each data item is considered once
– Possible to modify item as accessed
• Should implement as a distinct class that interacts with
the ADT
Copyright © 2019, 2015, 2012 Pearson Education, Inc. All Rights Reserved
, The ADT Bag
• Definition
– 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
Copyright © 2019, 2015, 2012 Pearson Education, Inc. All Rights Reserved