设为首页 加入收藏

TOP

3.6 C++(2)
2013-10-07 14:27:14 来源: 作者: 【 】 浏览:59
Tags:3.6

The STL also provides an explicit map container, based on balanced trees, that stores key-value pairs and provides O(logn) retrieva l of the value associated with any key. Maps might not be as efficient as O(1) hash tables, but it’s nice not to have to write any code whatsoever to use them. (Some non-standard C++(www.cppentry.com) libraries includea hash or hash_map container whose performance may be better.)

We also use the built-in comparison functions,which in this case will do string comparisons using the individual strings in the prefix.

With these components in hand, the code goes together smoothly. Here are the declarations:

图3.6  C++(www.cppentry.com)(1)  
The STL provides a template for deques; the notation deque<string> spe- cializes it to a deque whose elements are strings. Since this type appears several times in the program, we used a typedef to give it the name Prefix. The map type that stores prefixes and suffixes occurs only once, however, so we did not give it a separate name; the map declaration declares a variable statetab that is a map from prefixes to vectors of strings. This is more convenient than either C or Java, because we don’t need to provide a hash function or equals method.


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇3.6 C++(3) 下一篇3.6 C++(1)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: