KEMBAR78
STL Cheat Sheet | PDF
0% found this document useful (0 votes)
19 views2 pages

STL Cheat Sheet

This C++ STL Cheat Sheet provides an overview of various container types including sequence, associative, and unordered containers, along with their time complexities for common operations. It also lists container adapters and common algorithms with brief descriptions. Additionally, it includes code examples and necessary headers for implementation.

Uploaded by

Lavneesh Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

STL Cheat Sheet

This C++ STL Cheat Sheet provides an overview of various container types including sequence, associative, and unordered containers, along with their time complexities for common operations. It also lists container adapters and common algorithms with brief descriptions. Additionally, it includes code examples and necessary headers for implementation.

Uploaded by

Lavneesh Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C++ STL Cheat Sheet

Sequence Containers

vector: Dynamic array. Access O(1), Insert End O(1)*


list: Doubly linked list. Insert/Delete O(1) anywhere, Access O(n)
deque: Double-ended queue. Insert/Delete at both ends O(1)
array: Fixed-size array. Fast, limited to static size
forward_list: Singly linked list. Efficient front insert/delete

Associative Containers

set: Unique sorted elements. O(log n) insert/search


multiset: Sorted with duplicates. O(log n)
map: Key-value pairs, unique keys. O(log n)
multimap: Key-value pairs, duplicate keys. O(log n)

Unordered Containers

unordered_set/map: Use hash tables. Average O(1) insert/search, not sorted.


unordered_multiset/multimap: Allow duplicates, hash-based

Container Adapters

stack: LIFO. push, pop, top in O(1)


queue: FIFO. push, pop, front/back in O(1)
priority_queue: Max-heap. O(log n) insert/remove, O(1) top

Common Algorithms

sort(begin, end): Sort range in ascending


find(begin, end, val): Linear search
accumulate(begin, end, init): Sum range
remove(begin, end, val): Remove all val, use with erase
copy, copy_if, transform, reverse: Modify or rearrange

Code Example

vector<int> v = {1, 2, 3};


sort(v.begin(), v.end());
auto it = find(v.begin(), v.end(), 2);
int sum = accumulate(v.begin(), v.end(), 0);
v.erase(remove(v.begin(), v.end(), 2), v.end());
C++ STL Cheat Sheet

Headers

<vector>, <list>, <deque>, <array>, <set>, <map>


<unordered_map>, <unordered_set>, <stack>, <queue>, <algorithm>, <numeric>, <utility>

You might also like