class Vector<ValueType>| Constructor | |
| Vector() Vector(n, value) | Initializes a new vector. |
| Methods | |
| size() | Returns the number of elements in this vector. |
| isEmpty() | Returns true if this vector contains no elements. |
| clear() | Removes all elements from this vector. |
| get(index) | Returns the element at the specified index in this vector. |
| set(index, value) | Replaces the element at the specified index in this vector with a new value. |
| insertAt(0, value) | Inserts the element into this vector before the specified index. |
| removeAt(index) | Removes the element at the specified index from this vector. |
| add(value) | Adds a new value to the end of this vector. |
| mapAll(fn) mapAll(fn, data) | Calls the specified function on each element of the vector in ascending index order. |
| Operators | |
| vec[index] | Overloads [] to select elements from this vector. |
| v1 + v2 | Concatenates two vectors. |
| v1 += v2; | Adds all of the elements from v2 (or the single specified value) to v1. |
| Macro | |
| foreach(ValueType value in vec) | Iterates over the elements of the vector in ascending index order. |
Vector(); Vector(int n, ValueType value = ValueType());
n
elements, each of which is initialized to value;
if value is missing, the elements are initialized
to the default value for the type.
Usage:
Vector<ValueType> vec; Vector<ValueType> vec(n, value);
int size();
Usage:
int nElems = vec.size();
bool isEmpty();
true if this vector contains no elements.
Usage:
if (vec.isEmpty()) . . .
void clear();
Usage:
vec.clear();
ValueType get(int index);
Usage:
ValueType val = vec.get(index);
void set(int index, ValueType value);
Usage:
vec.set(index, value);
void insertAt(int index, ValueType value);
Usage:
vec.insertAt(0, value);
void removeAt(int index);
Usage:
vec.removeAt(index);
void add(ValueType value); void push_back(ValueType value);
vector class in the Standard Template Library,
this method is also called push_back.
Usage:
vec.add(value);
void mapAll(void (*fn)(ValueType value));
void mapAll(void (*fn)(ValueType value, ClientDataType & data),
ClientDataType & data);
Usage:
vec.mapAll(fn); vec.mapAll(fn, data);
ValueType & operator[](int index);
[] to select elements from this vector.
This extension enables the use of traditional array notation to
get or set individual elements. This method signals an error if
the index is outside the array range.
Usage:
vec[index]
Vector operator+(Vector v2);
Usage:
v1 + v2
Vector & operator+=(Vector v2); Vector & operator+=(ValueType value);
v2 (or the single
specified value) to v1. As a convenience, the
Vector package also overloads the comma operator so
that it is possible to initialize a vector like this:
Vectordigits; digits += 0, 1, 2, 3, 4, 5, 6, 7, 8, 9;
Usage:
v1 += v2; v1 += value;
foreach (ValueType value in vec) . . .