# Chapter 15 - Worked Exercises 2

## Exercise 1 - Vectors&#x20;

### Part 1&#x20;

1. Internally, how are the elements of a vector stored or represented? Are they contiguously in memory?
2. What operations are quick for vectors?&#x20;
3. What operations are relatively slow for vectors?&#x20;

### Part 2&#x20;

Given the following vector declaration:

```cpp
std::vector<int> numbers = {1, 2, 3, 5, 7, 11, 13};
```

Enumerate through the vector, and print each element:

* using a for-loop with indexing&#x20;
* using a range-based loop
* using iterators&#x20;

### Part 3&#x20;

#### Accessors&#x20;

1. Do vectors support random access (indexing)?&#x20;
2. How can you access the value of a vector at index `3`?&#x20;

#### Capacity&#x20;

1. How do you check if a vector is empty?
2. How do you get the capacity and size of a vector?&#x20;
3. What is the difference between the capacity of a vector and its size?&#x20;
4. Can the capacity of a vector ever be smaller than its size?

#### Modifiers

1. Show an example of inserting the value `100` at index `3` of a vector.
2. Show an example of inserting multiple elements from one vector into another.&#x20;
3. Show an example of removing the value at index `5` of a vector.&#x20;
4. Show an example of removing the values from index `2` to index `4` (non inclusive of `4`) from a vector.&#x20;
5. Show an example of removing all elements from a vector.&#x20;
