Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am looking for a data structure which can store values with index and also can be resized like a std::vector (but should be indexed so I can access it easily) is there any C++ standard library implementation of my problem?
What I am looking for is an array-type DS from which I can remove elements.
You can use std::deque which is also indexed sequence container like std::vector. It provids also std::deque::resize member function.
However, your requirement should be much more specific to suggest std::deque at first place than std::vector
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Let's say I have an array like:
{1,2,3}
So, for example, some function like:
arr.push(4);
Will make this array:
{4,1,2,3}
How do I do that?
It is not possible to push an element to an array. The size of an array remains the same through the lifetime of the array.
What can be done instead is to create a new, larger array and copy the elements from the old array. Such dynamic growable "array" data structure is provided for you in the standard library: std::vector.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Hi I need to type a code which calls the key and its values such as "Tokyo 10 23 32". I can't use arrays or vectors how can I store my data? Thanks.
Use std::map or std::unordered_map. std::map uses a Red-Black tree, and std::unordered_map uses a Hash Table.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How do you store contents in a vector and then sort them without creating a class?
Doing a class project and it requires to not use a class. The books are not helping.
This page has a good example, assuming you can put all of the elements in the vector at once. If you need to put them in one at a time, use std::vector::push_back.
Something like std::vector<std::string> v; v.push_back("hello"); std::sort(v.begin(), v.end());. Get better books.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to learn c++. I was struck at map in c++. Can someone qualitatively explain me what is a map and where is it more often used?
You are wrong about the internals of std::map - it uses a data structure with O(log n) insertion, query and delete times. IIRC, it's a red-black tree. To answer your question, the objects stored are of type map<int,int>::value_type which is std::pair<const int, int>. Here's the ref.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Is there some function in boost library which can sort key-value pairs?
e.g. keys being an array of double variables, and values are some index (integer) of the array.
What you probably want is a std::map<My_Double_Array, size_t> along with your own My_Double_Array class that wraps your array of double variables and provides a operator <() for sorting. Or simply std::map<std::vector<double>, size_t> might be all you need.