Summary of the basic usage of STL container vector and stl container vector
According to ACM program design, we use examples to demonstrate vector usage.
Methods: push_back (), insert (), erase (), clear (), size (), empty ();
Algorithm: reverse (), sort (), accumulate ().
1 # include
Scattered records of STL Learning (constantly updating), and stl learning is constantly updatedI write what I use, so I don't pay too much attention to typographical layout. I will sort it out after I write too much:
1: vector
2: The iterator cannot be set for the priority queue because there is no
3:
# Include
String str2 (str,); // truncate the str string Array 0 ~ Element 7, which comes with the
STL _ FUNCTION template, stl function Template
# Include # Include Using namespace std;
# Define MAX (T )\T max _ # T (T x, T y ){\Return x> y? X: y ;\}// Generate the following three types of functions during preprocessingMAX (int) // int max_int (int x, int y) {return x> y? X: y ;}MAX (double)MAX (string)
# Define mymax (T) max _ # T // The function name is replaced by a macro function
Int main (){Cout Co
STL container, stlArticle from http://blog.csdn.net/zhouyunxuanSeven sequence container types1. vector is a type of representation of arrays. It provides an automatic memory management function to dynamically change the length of a vector object and scale down as elements are added or deleted,It provides Random Access to elements. The time for adding and deleting elements at the end is fixed, but the complexity of inserting and deleting elements in th
rational use of custom assigns.
12th: Do not have unrealistic dependencies on the thread safety of STL containers.
To an STL implementation you can only expect:
It is safe to read multiple threads.
Multiple threads are safe to write to different containers.
You can't expect the STL library to free you from manual sy
directly. Partition algorithm, you can use List::sort instead of sort and stable_sort sorting. If you need to get a partial_sort or nth_element sort effect, you must use it indirectly. As described above, there are several ways to choose.In short, remember a word: If you want to save time, do not detours, also do not go the extra road! 4 Summary
Discussion technology is like a bottomless pit, which can often be easily extended by a few other technical points. So we need to look at the problem f
1. STL
STL (Standard Template Library) is an important part of the C ++ language standard. STL takes the form of template classes and template functionsProgramProvides various data structures andAlgorithmIf programmers can make full use of STLCodeSpace, execution time, and coding efficiency are greatly improved.
east"] = "first master, sunflower Collection ";...// Search ..If (namemap. Find ("Yue Bu group ")! = Namemap. End ()){...}Don't you think it's easy to use? In addition, the efficiency is very high, 1 million records, up to 20 strings. compare comparison, you can find the record you are looking for; 2 million record items, as long as 21 comparisons are used.The speed will never meet the actual needs. If there are 1 million records and I need to search frequently, 20 comparisons will also become
container (For details, refer to the article)
11 * use two methods to access the vector. 1. Vector: At () 2. Vector: operator [] OPERATOR [] is mainly used for compatibility with the C language. It can be operated like a C array. However, at () is our first choice because at () performs a boundary check.
12 compress a bloated vector, which is relatively simple. Use the assign of the vector to allocate the space for creating a new vector based on the actual size of the vector. For example:
Vecto
indirect layer of traits that separates algorithms from data structures! This makes the iterator a binder so that STL can work together!
6. Therefore,Iterator_traits must be designed with a special version when the input type is Pointer pointer and pointer to const!Introduction
The extract programming technology is used in STL,Brief description of extraction technology
Abstract: This article lists several basic STL map and STL set questions. By answering these questions, we explain the data structure in the STL associated container, finally, we raised the question about the built-in balanced binary tree library functions and map and set selection in Unix/Linux, and analyzed the advan
This article is only a personal learning process in conjunction with the online blog, the collation of STL, is only a brief introduction. Learn notes for individuals only. introduction of STL (excerpt from: Chenguang (morning))STL, the standard Template Library, is a highly efficient C + +
In the previous article, the story about stl_vector is just the beginning. In this article, we will analyze the details in vector.
Again, I have not read any books on stl source code analysis. I emphasize that this is to prevent others from misunderstanding that I copied it from other places.
The subsequent articles will detail the function implementation in vector.I try my best to make it small, and I can try my best to use my own language and my ow
container and its size can be changed. It can improve the Data Reading Capability Based on keywords.(2) provides a two-way positioner to read and write data.(3)Sorted by keywords and a comparison Function.(4)All keywords are unique..(5) a template that provides a general and independent data type.
4) for more information about map, see resources.
Download STL map resources
5) combined with the map method, a comprehensive test is provided.Code:
Details: https://zcheng.ren/2016/08/24/STLList/
C + + implemented vector since it cannot be implemented to quickly delete and insert elements, the STL designer then proposes to use list to solve the problem: through the memory of discontinuous space allocation node, through the link to operate, can quickly achieve this advantage.The nodes of the list include: pointer prev to the previous node, pointing to the pointer to the back node next;Iterator is
STL
1. Introduction to STL
STL (Standard Template Library) is a collection of software developed by the HP lab. It was developed by Alexander Stepanov, Meng Lee, and David R musser while working at the HP lab. Although it mainly appears in C ++, this technology has existed for a long time before it was introduced into
the use of CL parameters to compile, is still a side dish, will only use the simple Generation command, and will not write a perfect makefile.When I use this set of environment to try to compile STLport project, there is a situation where cl.exe exits directly. So in the end I also used the VS comes with Environment settings batch command: Vcvarsall.bat, sample in vs2012: C:\Program Files (x86) \microsoft Visual Studio 11.0\vc\ Vcvarsall.bat. You can compile the STLport-5.2.1 project by running
Introduction: This article describes the methods of exporting STL classes and classes containing STL in DLLs. Example source code
DLLs cannot directly export generic templates (generalized template), so if you are exporting an STL class, the template must be instantiated (instantiated) first. In addition, if the exported STL
), and if it is a pod type, the copy implementation of the algorithm library is called; otherwise traversal iterator _ The element between the first~_last and the new element is constructed at the _result start address at one by one.The Uninitialized_fill () looks like this: 1 template class _forwarditer, class _tp>2 inline void Uninitialized_fill (_forwarditer __first, 3 _forwarditer __last, /span>4 const _TP __x) 5 { 6 __ Uninitializ
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.