Collections and Linked Lists

Collections and Linked Lists - Collections and Linked Lists...

Info icon This preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
6/11/09 Collections and Linked Lists This week the focus is on the concept of a collection the importance of separating the interface from the implementation generic types and their use in collection classes the difference between fixed and dynamic implementations dynamically linked lists the Java Collections API
Image of page 1

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

View Full Document Right Arrow Icon
6/11/09 Outline Introduction to Collections A Bag Collection Array Implementation of a Bag Linked Lists Linked Implementation of a Bag
Image of page 2
6/11/09 Introduction to Collections We are used to collections of items: stamps, CDs, keys, etc. A collection is an object that serves as a repository for other objects A collection provides services to add, remove, and manage the elements it contains The underlying data structure used to implement the collection is independent of the operations provided
Image of page 3

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

View Full Document Right Arrow Icon
6/11/09 Introduction to Collections Collections can be separated into two categories linear: elements are organized in a straight line nonlinear: elements are organized in something other than a straight line Organization elements, relative to each other, is usually determined by the order in which they were added to the collection some inherent relationship among the elements
Image of page 4
6/11/09 Separating Interface from Implementation An abstract data type (ADT) is a set of data and the particular operations that are allowed on that data An ADT is considered abstract because the operations you can perform on it are separated from the underlying implementation A collection is an abstract data type defines interface operations through which the user can manage the objects in the collection,
Image of page 5

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

View Full Document Right Arrow Icon
6/11/09 Separating Interface from Implementation The details of how a collection is implemented to fulfill that definition should be an independent issue For every collection we examine, we should consider How does the collection operate, conceptually? What operations are included in the interface to the collection? What kinds of problems does the collection help us solve? How might the collection be implemented?
Image of page 6
6/11/09 Separating Interface from Implementation Class that uses the collection Class that implements the collection Interface to collection Services provided by collection that adhere to an interface
Image of page 7

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

View Full Document Right Arrow Icon
6/11/09 Generic Types Java permits us to define a class based on a generic type Our defined class will then be able to operate on, store, and manage objects whose type is not specified until the class is instantiated Example: we can define a Group class that stores and manages a group of objects. Using polymorphism, we can define Group to store references to the Object class
Image of page 8
6/11/09 Generic Types However, any type of object could then be stored in our Group , resulting in a loss of control A better approach is to define the Group to store a generic type T (a convention, though we can use any letter) class group<T> { // declarations and code that manages objects of type T }
Image of page 9

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

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern