Download presentation
Presentation is loading. Please wait.
Published byAlexis Goodman Modified over 9 years ago
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.