1 / 12

The List

The List. If A is success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut. Albert Einstein, Observer, Jan. 15, 1950. List. most general of list-oriented collections

starbuck
Download Presentation

The List

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The List If A is success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut. Albert Einstein, Observer, Jan. 15, 1950

  2. List • most general of list-oriented collections • an ordered collection (initially empty) of items (of some type) to which items may be added and removed. • cursored-list • cursor • operations relative to cursor • off list • errors • off list • list overflow

  3. List Operations • insertion? • before or after cursor? • at front • at end? • access • at cursor • off list? • deletion • at cursor • off list? • cursor after deletion • inverse of addition

  4. traversal • moving to front • advancing • end of list • search • key • from where • exhaustive search • list as stack • insert without advance • list as queue • insert with traverse to end • sequential order • insert with advance • sorted • traverse to find insertion point

  5. List Interface • generic • E • getKey • Comparable from java.lang • operations • insertion • deletion • access • length • traversal • search • off end? • iterator • exceptions • NoSpaceException • NoItemException

  6. Iterators • a device that allows traversal through a collection ADT • ADT extends Iterable<E> (from java.util) • iterator returns an Iterator over the ADT • interface Iterator<E> in java.util • methods • UnsupportedOperationException • extended for • implementation • must have intimate knowledge of ADT representation • place in same package & use package visibility in ADT

  7. List ADTContiguous Representation • “variable-sized” array • contiguity • reorganization (O(n)) • cursor is an index • instance variables • constructors • empty list • operations • insertion • create opening • shift items RL • cursor

  8. deletion • fill gap • shift items LR • cursor • removal of reference at length-1 • find • goal: move cursor • check each item in turn until found or off list • short circuit operator • negation using de Morgan’s law • iterator • create an iterator on this ADT • remaining operations

  9. ConListIterator • generic in item type (same as ConList) • iteration involves sequencing through index positions from 0 to length-1 • instance variables • list it is iterating • has its own cursor • must keep track of current position • constructor • package visibility • only classes in package can create • initialize cursor • methods • access ConList instance variables directly (package visibility)

  10. List ADTLinked Implementation • sequentially-linked structure • sequential processing natural • cursor? • cursor is Node reference • off list • insertion • in front of cursor • precursor • cursor pairs • header node • at end?

  11. representation • sequentially linked structure with header and two cursors • empty list • off list? • length • keep count • comparison with contiguous • insert/remove O(1) vs O(n)

  12. The End

More Related