Hello there, I am doing homework assignmet on STL, and I have a question. One of the function need to take two different arguments and create a data structure, but I'm not sure which container to use. I tried using queue. push but it says that this function can't take two argumenst. Is multiset is better?
std::vector
Store elements in given order and tightly packed in memory (like arrays do).
std::list
Store elements in given order but not tightly packed in memory. Because the elements are linked, insertion and removal of elements is usually (theoretically) faster than for std::vector.
std::queuestd::stack
These are like simplified lists. You use them to make it clear to others the fashion in which you add and remove elements. Queues: FIFO (first in first out), stacks: LIFO (last in first out).
std::set
Store a single copy of an element, also it sorts its contents!
If you add to an std::set<int> the values
{4, 3, 3, 3, 1, 5}
it will contain
{1, 3, 4, 5}
std::multiset
Similar to a set, but copies of the same value are permitted.
If you add to an std::multiset<int> the values
{4, 3, 3, 3, 1, 5}
it will contain
{1, 3, 3, 3, 4, 5}
std::map
Stores key and element pairs. You use the key to access an element. For instance, arrays are a type of map. my_array[11] = 3; // 11 is the key, 3 is the element
However "real" maps can use things other than indexes as keys: my_map["eleven"] = 3; // "eleven" is the key, 3 is the element
std::multimap
Similar to map, but you can have more elements mapped to a single key. So you can use a key to get a list of elements instead of a single element.
So to answer the question in the thread's title... well I guess you could use a multiset instead of a queue if you wanted to have your elements automatically sorted...