1 / 9

Vectors, Lists, Sequences

Vectors, Lists, Sequences. Vectors. Linear sequence s of n elements e rank – number of elements before e in s Vector supports access to elements via their ranks elemAtRank(r) replaceAtRank(r, e) insertAtRank(r, e) removeAtRank(r) size isEmpty. Vector Implementation.

alanham
Download Presentation

Vectors, Lists, Sequences

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. Vectors, Lists, Sequences

  2. Vectors • Linear sequence s of n elements e • rank – number of elements before e in s • Vector supports access to elements via their ranks • elemAtRank(r) • replaceAtRank(r, e) • insertAtRank(r, e) • removeAtRank(r) • size • isEmpty

  3. Vector Implementation • Extendable array implementation • when array is full, allocate new array of 2xs the size • copy elements into new array • Efficiency?

  4. Lists • Access/modify by “position” instead of rank • insertBefore(p, e) • insertAfter(p, e)

  5. Sequences • Supports functionality of vector and list • Additional functions • atRank(r) – returns position • rankOf(p) – returns rank

  6. Bubble Sort • Bubble sort • make n passes through a sequence and swap two elements if they are out of order (5 7 2 6 9 3)

  7. Bubble Sort on a Sequence • Algorithm

  8. Iterators • Step through a data structure one element at a time • hasNext() • Input: none Output: Boolean • next() • Input: none Output: Object

  9. Exercises • Give an adapter class to support the Stack interface using the functions of the vector ADT

More Related