Posts Tagged ‘STL’

Maps in C++

C++ thumb CPP

Maps are one of the most useful datastructures in C++ and there is no excuse for not knowing it. Here is a basic example that shows how you can use it: See also C++ Reference: general information and example Map is ordered collection (source)

Vectors in C++

C++ thumb CPP

Minimal Example Output: Vector initialization Nested Vectors Output: Initialize nested vectors Output with the script above: You could also do it this way: Some more Reverse the order With reverse (source): See also C++ Reference: General information and example Iterating over 2-dimensional STL vector C++

Sets in C++

C++ thumb CPP

As find is logarithmic in size() (source: C++ Reference), the membership test is also in . Sets of structs If you want to create a set of structs, you have to create a comperator: See also C++ Reference: general information and example How to check that an element is in a std::set?

Stacks in C++

C++ thumb CPP

Minimum Example Maximum number of elements 100,000,000 could be added without any problems. See also C++ Reference: general information and example General information about the datastructure stack