Chapter 5: Vectors, Lists, and Sequences

5.1 Vectors

5.1.1 The Vector Abstract Data Type
[Vectors.pdf 1-2-3-4]
5.1.2 A Simple Array-Based Implementation
[Vectors.pdf 5-6-7-8]


Insertion


Deletion


Performance
5.1.3 An Extendable Array Implementation
html-5.2
html-5.3
Fixed Length Capacity Increment

5.1.4 The STL vector Class


5.2 Lists

5.2.1 Node-Based Operations and Positions
Sequences.pdf 1-2-3-4-5

Position ADT
[Sequences.pdf 6]

5.2.2 The List Abstract Data Type

[Sequences.pdf 7]
html-5.4

5.2.3 Doubly Linked List Implementation

[Sequences.pdf 8]

html-5.5 (Node)



Using Positions
html-5.6 (Positions)
html-5.7 (InvalidPositionException)

Insertion
[Sequences.pdf 9]
We visualize operation insertAfter(p, X), which returns position q

Deletion
[Sequences.pdf 10]
We visualize remove(p), where p = last()

html-5.10 (NodeList1)
html-5.11 (NodeList2)

Performance

5.2.4 The STL list Class
list<>
size()
empty()
front()
back()
push_front(e)
push_back(e)
pop_front()
pop_back()

Similarities and Differences with Our List ADT


5.3 Sequences

5.3.1 The Sequence Abstract Data Type
[Sequences.pdf 12-13]
Multiple Inheritance in the Sequence ADT
html-5.12 (Sequence)

5.3.2 Implementing a Sequence with a Doubly Linked List
All of the functions of the list ADT can be easily implemented to run O(1) time.

html-5.13 (NodeSequence1)
html-5.14 (NodeSequence2)

5.3.3 Implementing a Sequence with an Array

[Sequences.pdf 14]



5.3.4 Comparing Sequence Implementations

[Sequences.pdf 15]

Operation
Array
List
size, isEmpty
1
1
atRank, rankOf, elemAtRank
1
n
first, last, before, after
1
1
replaceElement, swapElements
1
1
replaceAtRank
1
n
insertAtRank, removeAtRank
n
n
insertFirst, insertLast
1
1
insertAfter, insertBefore
n
1
remove
n
1


5.5 Iterators

5.5.1 Iterator Functions
[Sequences.pdf 16]

html-16 (ObjectIterator)

STL Iterators
html-17 (STLiterator)


5.6 A Hierarchy of Sequence ADTs

5.6.1 Functions of a Container
A container is a data structure that stores and organizes a collection of objects, called the elements of the container, and provides access to them through the functions of an abstract data type.

The Container ADT
The functions of a container:

5.6.2 Inspectable Containers

Containers that do not provide update functions are called inspectable containers.

5.6.3 Inheritance Structure of Sequence ADTs

example.cpp