Maps, indexed data structures

We consider now another case study. this one involves the use of the map data type, which is a dictionary container. We are going to use a map to represent a graph. The key values in the graph will represent cities, while the index values will represent distances between cities.

In fact, we are going to use dictionaries within dictionaries. A string vector will be a map that is indexed by strings (the city names) and will hold integers (the distances to the city). A graph will be a map that is indexed by string (again, city names), and will hold string vectors (the distances from that city to the next).

Maps can be used like sparse arrays, and thus can be initialized as shown here.

[audio] [real] Text to accompany slide16, in Chapter 16 of An Introduction to Object-Oriented Programming