Our third implementation is in C++(www.cppentry.com). Since C++(www.cppentry.com) is almost a superset of C, it can be used as if it were C with a few notational conveniences,and our original C version of markov is also a legal C++(www.cppentry.com) program. A more appropriate use of C++(www.cppentry.com), however, would be to define classes for the objects in the program, more or less as we did in Java; this would let us hide implementation details.We decided to go even further by using the Standard Template Library or STL, since the STL has built-in mechanisms that will do much of what we need. The ISO standard for C++(www.cppentry.com) includes the STL as part of the language definition.
C++(www.cppentry.com)是C的一个超集——这只是较早的说法,实际上,这种说法在渐渐地发生 改变。以Standley Lippman所著的《C++(www.cppentry.com) Primer》一书为首的更多的言论认为,就目前学习C++(www.cppentry.com)而言,可以认为它是一门独立的语言。它兼容C语言,但是并不依赖C 语言。
标准模板库(STL),很多传统的C++(www.cppentry.com)教材(特别是国内的)还没有介绍到这 一部分。标准模板库(STL)为C++(www.cppentry.com)开发者提供了数据存取和排序、运算的一揽子 方案,包括容器、算法等。
The STL provides containers such as vectors,lists, and sets, and a family of fundamental algorithms for searching, sorting,inserting, and deleting. Using the template features of C++(www.cppentry.com), every STL algorithm works on a variety of contain- ers, including both user-defined types and built-in types like integers. Containers are expressed as C++(www.cppentry.com) templates that are instantiated for specific data types; for example, there is a vector container that can be used to make particular types like vector<int> or vector<string>. All vector operations, including standard algorithms for sorting, can be used on such data types.
In addition to a vector container that is similar to Java’s Vector, the STL provides a deque container. A deque (pronounced“deck”) is a double-ended queue that matches what we do with prefixes: it holds NPREF elements, and lets us pop the first element and add a new one to the end, in O(1) time for both. The STL deque is more general than we need, since it permits push and pop at either end, but the performance guarantees make it an obvious choice.