6.13. 搜索树操作¶
6.13. Search Tree Operations
在我们查看实现之前,让我们回顾一下映射 ADT 提供的接口。你会发现,这个接口与 Python 字典非常相似。
Map()创建一个新的空映射。put(key, val)向映射中添加一个新的键值对。如果键已经存在于映射中,它会用新值替换旧值。get(key)接受一个键并返回映射中存储的匹配值,如果没有匹配的值,则返回None。del使用del map[key]的形式删除映射中的键值对。size()返回映射中存储的键值对的数量。in对于形式为key in map的语句,如果给定的键在映射中,返回True,否则返回False。
Before we look at the implementation, let’s review the interface provided by the map ADT. You will notice that this interface is very similar to the Python dictionary.
Map()creates a new empty map.put(key, val)adds a new key--value pair to the map. If the key is already in the map, it replaces the old value with the new value.get(key)takes a key and returns the matching value stored in the map orNoneotherwise.deldeletes the key--value pair from the map using a statement of the formdel map[key].size()returns the number of key--value pairs stored in the map.inreturnTruefor a statement of the formkey in mapif the given key is in the map,Falseotherwise.
最后更新:
2024年9月13日
创建日期: 2024年9月9日
创建日期: 2024年9月9日