
Assign 1 due next Wed
•Web announcements for late-breaking news
MLK, Jr Day on Monday, no lecture
Today’s topics
•CS106 class library: Vector, Grid, Stack, Queue
Reading
•Handout 14 (today & next)
A note about arrays/pointers
•Covered in Ch. 2, but we wait to introduce until we have a good use
for them, so don't worry for now
Terman cafe today after lecture
Client includes interface file as usual
#include "vector.h"
Client must specialize to fill in the placeholder
Cannot use Vector without qualification, must be Vector<char>,
Vector<locationT> , ...
Applies to declarations (variables, parameters, return types) and calling
constructor
Vector is specialized for its element type
Attempt to add locationT into Vector<char> will not compile!
Indexed, linear homogenous collection
Knows its size
Access is bounds-checked
Storage automatically handled (grow & shrink)
Convenient insert/remove
Deep-copy on assignment, pass/return-by-value
Usage
Constructor creates empty vector
Add/insert adds new element
Access elements using setAt, getAt or operator []
Useful for:
every kind of list you can imagine!
template <typename ElemType>
class Vector {
public:
Vector();
~Vector();
int size();
bool isEmpty();
ElemType getAt(int index);
void setAt(int index, ElemType value);
void add(ElemType value);
void insertAt(int pos, ElemType value);
void removeAt(int pos);
};