presentation4

presentation4 - Container Classes YHL Wednesday, September...

Info iconThis preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
YHL Container Class 1 Container Classes Wednesday, September 21, 2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
YHL Container Class 2 Why Container Classes? Many programs use arrays, vectors, lists, queues, stacks, sets to store information. Both C++ and Java provide container classes that automatically manage memory, i.e. they allocate additional memory when more elements are added. The supported container classes greatly reduce the amount of code and programming needed and improve productivity. Container classes and OOP are closely related: – a container can hold objects of derived classes – polymorphism properly invokes the correct methods Wednesday, September 21, 2011
Background image of page 2
YHL Container Class 3 Container Class (For Code Reuse) A container needs to be able to hold items of different types (i.e. classes). Examples – list of strings, integers, floating points, student objects – queues of customer objects, car objects maps: name address, student ID name, course title classroom C++ standard template library (STL) and Java container classes provide such functionality. Wednesday, September 21, 2011
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
YHL Container Class 4 Select Container Class random or sequential accesses? allow unique or duplicate items? O(1) or O(N) for array-like access (using [index]) efficient insert / delete? – front – end – middle Java containers cannot store primitive types (int, char, float . ..) and can store objects only. Primitive types, however, have corresponding object types (e.g. Integer, Boolean) that can be held in containers. C++ containers can store primitives. Wednesday, September 21, 2011
Background image of page 4
YHL Container Class 5 Efficiency operation vector deque list array-like access O(1) O(1) O(N) insert/delete at front O(N) O(1)+ O(1) insert/delete at end O(1)+ O(1)+ O(1) insert/delete in middle O(N) O(N) O(1) N: current number of items Wednesday, September 21, 2011
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
YHL Container Class 6 Java Containers Wednesday, September 21, 2011
Background image of page 6
YHL Container Class 7 Java List Wednesday, September 21, 2011
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
YHL Container Class 8 Wednesday, September 21, 2011
Background image of page 8
YHL Container Class 9 Interface and Class A Java interface serves as an abstract class and cannot be instantiated. An interface can be implemented by classes. Typically, an interface is a common base for several related classes, for example, interface List as the base of ArrayList, LinkedList, Stack, and Vector. Wednesday, September 21, 2011
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
YHL Container Class 10 Wednesday, September 21, 2011
Background image of page 10
YHL Container Class 11 Wednesday, September 21, 2011
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
YHL Container Class 12 Wednesday, September 21, 2011
Background image of page 12
YHL Container Class 13 Wednesday, September 21, 2011
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
YHL Container Class Iterators Iterators are easy ways to traverse a collection of objects In general, don’t assume an order for how objects are visited Documentation for a container class will say if any order is allowed. In general, changing the iterated container while iterating
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 161

presentation4 - Container Classes YHL Wednesday, September...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online