This question already has answers here:
How to choose between map and unordered_map?
(5 answers)
Closed 5 years ago.
According to: This Tutorial
I can't understand the difference between std::map and std::unorderedmap. When and Why we should use Map and Unorderedmap?
As I've read in tutorial you provided, search speed in std::unorderedmap is O(1). While in std::map it's O(log2(n)), where n is size of the map.
So if you have to call std::find often, you can consider this option. While choosing hash function isn't an easy task.
Related
This question already has answers here:
std::queue iteration
(10 answers)
Closed 3 years ago.
I was trying to iterate over a STL stack in c++ but was unable to do so.
Is it even possible to iterate over a C++ STL Stack or Queue without popping(Like vectors)?
No, you cannot iterate over a std::queue since that is not its purpose.
A container that allows fast insertion at both ends, as well as iteration, is std::deque. Note that iteration is slower than for a std::vector, but insertion/removal at the beginning is much faster.
This question already has answers here:
What really is a deque in STL?
(8 answers)
Closed 6 years ago.
I am learning stl and learn how to use all stl containers and i need to knew
when i have to use deque in my program.
what is the different between deque and other stl containers
http://www.cplusplus.com/reference/deque/deque/
You can push elements to a deque on both ends.
Example:
You can use a deque as "history".
The oldest items are in front.
Now you have easy access on the newest element and the oldest. (It is good for a undo function)
This question already has answers here:
Flatten a list in Prolog
(7 answers)
Closed 7 years ago.
I want to be able to turn
this:
[[[a],b],c]
into this:
[a,b,c]
with a constantly changing lists, so far I've done this:
a([[[A],B],C]).
strechList(List,C):-
List=[H,T],
append(T,List1,C),
strechList(H,List1).
strechList(A,A).
but it doesn't work.
That predicate is called 'flatten'. It's built-in if you're using SWI-Prolog.
Also check this answer.
This question already has answers here:
What requirements must std::map key classes meet to be valid keys?
(4 answers)
Closed 8 years ago.
I have to keep count of the occurrences of various sub matrices that occur in a matrix. Can I use a map, keeping the Key as a 2D matrix and the Value as the count?
If I can, then what will the syntax be?
This has been addressed more generally in the following post:
What requirements must std::map key classes meet to be valid keys?
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
C++ struct sorting
Is it possible to sort a vector in C++ according to a specified sorting method, like used in Java's Collections.sort that takes a Comparator?
Yes. See the answers to this question from this morning: C++ struct sorting
Yes, it is. Take a look here for an example.