Calling keys in C++ for their values [closed] - c++

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.

Related

How to create an empty std::map object? [closed]

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
I tried this:
std::map<int,int> m;
and it works -- m becomes an empty map. But this approach may not work if the compiler choose to not initialize m to an empty map by default. Better solution?
Any better solution?
Taking your question literally, no. There is no better solution.
This will create a default constructed, and therefore empty std::map<int,int>.
std::map<int,int> m;

storing contents in vectors in C++ language [closed]

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.

data type of a and b in map<int,int> a,b [closed]

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.

can 0-1 knapsack be implemented using 1D array? [closed]

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
I found implementation using 2D array http://www.geeksforgeeks.org/dynamic-programming-set-10-0-1-knapsack-problem/. But how to implement it using 1D array and if it is not possible then why?
Note that each of values in the current row uses only elements of the current and previous rows. Hence you can implement the algorithm with an array K[2][W], which is the same as using an array K[2*W] with some additional trivial index calculations

How to sort a pair of keys and values using boost? [closed]

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.