In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the example analysis of the algorithm of STL components, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand it.
STL provides a large number of template classes and functions that can be used in OOP and general programming. All STL's about 50 algorithms are completely generic and do not depend on any particular data type. The following sections describe the three basic STL components:
1) the iterator provides a way to access objects in the container. For example, you can use a pair of iterators to specify a range of objects in list or vector. An iterator is like a pointer. In fact, the pointer of C++ is also an iterator. However, iterators can also be class objects that define operator* () and other operator-like methods like pointers.
2) A container is a data structure, such as list,vector, and deques, which is provided in the method of a template class. To access the data in the container, you can use an iterator output by the container class.
3) the algorithm is a template function used to manipulate the data in the container. For example, STL uses sort () to sort the data in a vector and find () to search for objects in a list. The functions themselves are independent of the structure and type of data they operate on, so they can be used on any data structure, from simple arrays to highly complex containers.
Functions and function objects
In STL, functions are called algorithms, which means they are more generic than standard C library functions. The STL algorithm is implemented as a template class or template function by overloading the operator () function. These classes are used to create function objects that perform various operations on the data in the container. The following sections explain how to use functions and function objects.
Functions and assertions
You often need to perform user-defined operations on the data in the container. For example, you might want the STL algorithm that traverses all objects in a container to be able to call back its own functions. For example
# include # include / / Need random (), srandom () # include / / Need time () # include / / Need vector # include / / Need for_each () # define VSIZE 24 / / Size of vector vector v (VSIZE); / / Vector object / / Function prototypes void initialize (long & ri); void show (const long & ri); bool isMinus (const long & ri); / / Predicate function int main () {srandom (time (NULL)) / / Seed random generator for_each (v.begin (), v.end (), initialize); / / call the ordinary function cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.