vectors

Dec 2, 2017 at 11:08pm
a.
Last edited on Dec 12, 2017 at 1:07am
Dec 2, 2017 at 11:17pm
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.

Dec 2, 2017 at 11:21pm
C
Last edited on Dec 12, 2017 at 1:07am
Dec 3, 2017 at 12:00am
Dec 3, 2017 at 12:42am
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 Dec 3, 2017 at 12:43am
Topic archived. No new replies allowed.