C++ Standard Library Data Structures and Algorithms
Classified in Computers
Written on in English with a size of 146.78 KB
C-Style Arrays
In stack: int a[3] = {0, 1, 2};
In heap: int* b = new int[3];
Sorting
std::sort(myvector.begin(), myvector.end());
Example 2: std::sort(myvector.begin(), myvector.end(), myCompFunction);
mylist.sort()
or mylist.sort(compare_nocase);
bool compare_nocase(const std::string& first, const std::string& second) { return first < second; }
Templated Classes
Include template <typename T>
above the header.
Each function has a template declaration:
template <typename T>
class_name<T>::getmax () {
// ...
}
typedef list_iterator iterator;
Strings
str.substr(3, 5)
(starts at position 3, length 5)
str1.compare(str2) != 0
str.length()
Lists
iterator insert(iterator position, const value_type& val);
(returns pair)
Maps
std::map&