[cs13001] Vectors.

Mikhail Nesterenko mikhail at cs.kent.edu
Sun Nov 18 10:09:07 EST 2012


> 
> -What exactly does items.push_back(55) do? Does it add an extra
> array element and give it the value of 55? Does it add 55 memory
> locations?

it appends 55 to vector "items"


> -Same for items.resize(newSize), does newSize mean the new number of array elements inside of it?

it sets the size of the array to "newSize".


 
> -We stated that a vector can be passed by value, reference and
> return, while arrays can only be passed by reference, but not by
> value nor returned, is that correct?

yes

> 
> -What does this line mean:
> 
> vector <int> v;
> v = items;
> items.swap(v);  <<<<<<<<  
>  		  What does this line mean? What about v are we swapping?
> 

The contents of vectors "items" and "v" are swapped


> -I know what the mutator and accessor are, but what exactly is a
>   simple setter?

setter is another name for mutator. Getter is another name for accessor.

> 
> -What does this do? v.insert(v.end()-2 , 55);

inserts 55 before the second from the back element of vector "v"


> 
> -Why do we have to reassign after using an iterator for update? Is
> it to get rid of the info now stored in it?

Update might reallocate the array used to store the vector, thus the
memory location that the iterator points to may no longer belong to
the vector.

> 
> -There is a question that says "When are vectors equal?", when is that?

Two vectors are equal when they are the same size and content.


Thanks,
--
Mikhail


More information about the cs13001 mailing list