formatting

This commit is contained in:
Jidong Xiao
2023-10-20 10:24:50 -04:00
parent 284f8d452d
commit 4ab7ed8f61

View File

@@ -72,7 +72,7 @@ The mechanics of using std::pairs are relatively straightforward:
- std::pairs are a templated struct with just two members, called first and second. Reminder: a struct - std::pairs are a templated struct with just two members, called first and second. Reminder: a struct
is basically a wimpy class and in this course you arent allowed to create new structs. You should use classes is basically a wimpy class and in this course you arent allowed to create new structs. You should use classes
instead. instead.
- To work with pairs, you must #include <utility>. Note that the header file for maps (#include <map>) - To work with pairs, you must #include &lt;utility&gt;. Note that the header file for maps (#include &lt;map&gt;)
itself includes utility, so you dont have to include utility explicitly when you use pairs with maps. itself includes utility, so you dont have to include utility explicitly when you use pairs with maps.
- Here are simple examples of manipulating pairs: - Here are simple examples of manipulating pairs:
```cpp ```cpp
@@ -103,8 +103,12 @@ std::pair&lt;const key_type, value_type&gt;
- Weve used the [] operator on vectors, which is conceptually very simple because vectors are just resizable - Weve used the [] operator on vectors, which is conceptually very simple because vectors are just resizable
arrays. Arrays and vectors are efficient random access data structures. arrays. Arrays and vectors are efficient random access data structures.
- But operator[] is actually a function call, so it can do things that arent so simple too, for example: - But operator[] is actually a function call, so it can do things that arent so simple too, for example:
```cpp
++counters[s]; ++counters[s];
For maps, the [] operator searches the map for the pair containing the key (string) s. ```
- For maps, the [] operator searches the map for the pair containing the key (string) s.
If such a pair containing the key is not there, the operator: If such a pair containing the key is not there, the operator:
1. creates a pair containing the key and a default initialized value, 1. creates a pair containing the key and a default initialized value,
2. inserts the pair into the map in the appropriate position, and 2. inserts the pair into the map in the appropriate position, and