Skip to content

Commit 4f1d1f2

Browse files
committed
Add reverse, unordered_set, set, unordered_map
1 parent 115eb87 commit 4f1d1f2

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ getline(cin, s); // Read line ending in '\n'
372372
373373
## `vector` (Variable sized array/stack with built in memory allocation)
374374
375-
376375
```cpp
377376
#include <vector> // Include vector (std namespace)
378377
vector<int> a(10); // a[0]..a[9] are int (default size is 0)
@@ -412,7 +411,7 @@ a.first; // "hello"
412411
a.second; // 3
413412
```
414413
415-
## `map` (associative array - usually implemented as red-black trees)
414+
## `map` (associative array - usually implemented as binary search trees)
416415
417416
```cpp
418417
#include <map> // Include map (std namespace)
@@ -423,6 +422,39 @@ for (auto& p:a)
423422
a.size(); // 1
424423
```
425424

425+
## `unordered_map` (associative array - usually implemented as hash table)
426+
427+
```cpp
428+
#include <unordered_map> // Include map (std namespace)
429+
unordered_map<string, int> a; // Map from string to int
430+
a["hello"] = 3; // Add or replace element a["hello"]
431+
for (auto& p:a)
432+
cout << p.first << p.second; // Prints hello, 3
433+
a.size(); // 1
434+
```
435+
436+
## `set` (store unique elements - usually implemented as binary search trees)
437+
438+
```cpp
439+
#include <set> // Include set (std namespace)
440+
set<int> s; // Set of integers
441+
s.insert(123); // Add element to set
442+
if (s.find(123) != s.end()) // Search for an element
443+
s.erase(123);
444+
cout << s.size(); // Number of elements in set
445+
```
446+
447+
## `unordered_set` (store unique elements - usually implemented as a hash set)
448+
449+
```cpp
450+
#include <unordered_set> // Include set (std namespace)
451+
unordered_set<int> s; // Set of integers
452+
s.insert(123); // Add element to set
453+
if (s.find(123) != s.end()) // Search for an element
454+
s.erase(123);
455+
cout << s.size(); // Number of elements in set
456+
```
457+
426458
## `algorithm` (A collection of 60 algorithms on sequences with iterators)
427459

428460
```cpp
@@ -431,4 +463,5 @@ min(x, y); max(x, y); // Smaller/larger of x, y (any type defining <)
431463
swap(x, y); // Exchange values of variables x and y
432464
sort(a, a+n); // Sort array a[0]..a[n-1] by <
433465
sort(a.begin(), a.end()); // Sort vector or deque
466+
reverse(a.begin(), a.end()); // Reverse vector or deque
434467
```

0 commit comments

Comments
 (0)