diff --git a/lectures/15_maps_I/README.md b/lectures/15_maps_I/README.md index 937722d..1583157 100644 --- a/lectures/15_maps_I/README.md +++ b/lectures/15_maps_I/README.md @@ -49,9 +49,6 @@ constructor, and as the example shows there are other ways of constructing pairs The two statements at the end are commented out because they cause syntax errors: - In (a), the first entry of p3 is const, which means it can’t be changed. - In (b), the two pairs are different types! Make sure you understand this. -- Returning to maps, each entry in the map is a pair object of type: -std::pair<const key_type, value_type> -- The const is needed to ensure that the keys aren’t changed! This is crucial because maps are sorted by keys! ## 15.2 STL Maps: Associative Containers @@ -65,23 +62,20 @@ text file on which that string occurs. A particular instance of a map is defined (declared) with the syntax: ```cpp -std::map<key_type, value_type> var_name +std::map var_name ``` - In our first two examples above, key type is a string. In the first example, the value type is an int and in the second it is a std::vector<int>. -- Entries in maps are pairs: std::pair<const key_type, value_type>, or just std::pair<key_type, value_type>. +- Entries in maps are pairs: std::pair<const key_type, value_type>, the const is needed to ensure that the keys aren’t changed! This is crucial because maps are sorted by keys! - Map iterators refer to pairs. - Map search, insert and erase are all very fast: O(log n) time, where n is the number of pairs stored in the map. -- Map search, insert and erase are O(log n). -First, let’s see how some of this works with a program to count the occurrences of each word in a file. We’ll look -at more details and more examples later. ## 15.3 Counting Word Occurrences -Here’s a simple and elegant solution to this problem using a map: +First, let’s see how some of this works with a program to count the occurrences of each word in a file. Here’s a simple and elegant solution to this problem using a map: ```cpp #include