× Home (CS 211) Notes Projects Waxman's Website

General

A vector is a resizable array. Like arrays, vectors uses contiguous storage of their elements in memory. the [] operator works the same as they do for arrays; they can be used to access elements. In order to use vectors, the vector library needs to be included in the header.
vector1

The syntax for using vectors is:
vector <data_type> variable_name;
Within the brackets, <>, is any data type such as int, char, strings, or objects. It can be any data type either compound or primative types.

declares a empty vector x of integers.
vector2
declares a vector y of integers with a size of 10 and all elements initialize to 0.
vector3
declares a vector z of integers with a size of 5 and all elements initialize to 3.
vector4

Functions

There are 4 main funcations for vectors:

vector5

Related:Towers of Hanoi