vectors

a.
Last edited on
What have you tried? Several problems caused by your lack of content:

We don't really know what language you're studying, C or C++ would be a guess, and looking a the questions, C would be my guess.

What do you mean by "vector"? Using the sizeof() operator on a std::vector will not give you the "size" (number of elements) of the vector.

We have no idea what you studied in your lectures and therefore don't know why you would need to use pointers.

We also have no idea what is inside your sorting, so we have no idea why you would want to use pointers instead of references.

Lastly we also don't know what sorting algorithms you're trying to implement.

C
Last edited on
See http://en.cppreference.com/w/cpp/container/vector/vector example at the bottom for an example of initialization list.
std::vector<std::string> words1 {"the", "frogurt", "is", "also", "cursed"}; is an example of the initializator list.

(b.) I think the premise of this question is invalid or ambiguous. sizeof is not used to find the length of the vector, and it also technically isn't a function. vector.size() is what should be used to find the number of elements in a vector. If by "length", you mean the size in bytes of internal data on the heap, you can do my_vector.size() * sizeof(TypeOfMyVector), ex: my_vector.size() * sizeof(int).

For the other questions, you should put some more effort into trying to solve it yourself first, and then come back when you have a specific question.
Last edited on
Registered users can post here. Sign in or register to post.