iterators//list//Error : Error C2440: "Initialize": Cannot convert from "int" to "std::_list_iterator//Description List//this inner class overloads the = operator constructor to accept a pointer /*The begin () method returns an iterator to the element of the linked header*/ListLdata.begin (); //Emphasizing that current is an inner class is not a pointer but the function of an iterator is equivalent to a pointer to a list element//iterator step is a byte of element type size for(curre
Common capabilities of STL containers
All containers provide "value semantics" rather than "reference semantics". When an element is placed in a container, the internal copy or move, rather than the reference of the management element.
Elements have their specific order within the container.
In general, each operation is not completely secure, and the caller needs to ensure that the arguments passed to the operation function meet the
Method:1. Create a new application.mk under the JNI directory; Add App_stl: = Stlport_static to the right of the value can also be replaced by the following:System-Uses the default minimal C + + runtime, which makes the resulting application small and memory-intensive, but some features will not supportStlport_static-use STLport as a static library, which is highly recommended by the Android Development NetworkStlport_shared-stlport as a dynamic
Some people use the next_permutation () function in the C ++ algorithm library to get a full arrangement and find that the final full arrangement is not enough. I don't know why. I thought the standard library function was wrong, in fact, this standard library function has preconditions, that is, the parameters must be arranged in non-descending order.
Let's tak
The list in the C + + standard library has recently been used, but it is not supported by multithreading. So I decided to change it to support multithreading.
Thinking above simpler, imitate C # below the pattern, inherit list, and then to use the method to overload, add lock, become support multithreading. Implementation of the time or found a lot of problems, mainly or C + + terrible syntax, I have been doing several days. Here's a summary.
First, f
3. STL and generic programming
Introduction
The STL programming mode is generic programming, which has the following core ideas:
ForAlgorithmThe assumption of as few data types as possible, and vice versa, so that algorithms and data can collaborate as well as possible.
Expressing algorithms with minimal assumptions about data processing actions, and vice versa,
Thus mak
}TemplateBOOL Operator{Return (! ( Y }TemplateBOOL Operator>= (const pair{Return (! ( x }TemplatePair{Return (Pair}#endifSummarize the above code to discover:1) pair supports three constructors for initialization2) A pair of values in a pair can be of different data types3) Two values for pair are accessed via Pair.first and Pair.second, respectively4) often use Make_pair5) Pair support size comparison, at this time class T1 and class T2 two classes to be the same or to support the comparison s
that describes whether to insert it.Key_compGrammar:Key_compare Key_comp ();The Key_comp () function returns a function that compares key.Lower_boundGrammar:Iterator Lower_bound (const key_type key);The Lower_bound () function returns an iterator that points to the first element of the key value >=key in Multimap.Max_sizeGrammar:Size_type max_size ();The Max_size () function returns the maximum number of elements that Multimap can hold.RbeginGrammar:Reverse_iterator Rbegin ();The Rbegin () func
Vector:
When writing a vector, we encounter the following code:
For (Int J = 0; j V1.size (); J ++) {printf ("% d", J, V1 [J]); printf ("% d", v1.size ()); if (V1 [J] = 4 ){V1.insert (v1.begin (),5); // Insert an element before accessing the element. Then, the element sequence is moved one by one, so all the elements accessed are 4.J ++;} getchar ();}
Notice: If you need to insert and delete elements in traversal, The v1.size cannot be fixed. Otherwise, the elements at the end will be missed.
The header file # include 1) how to define a list object# Include Int main (void){List }
2) use the list member functions push_back and push_front to insert an element to the list.Clist. push_back ('A'); // put an object behind a list
Clist. push_front ('B'); // put an object in front of a list
3) use the list member function empty () to determine whether the list is empty.If (clist. Empty () {printf ("This list is empty ");}
4) Use List List For (citerator = clist. Begin (); citerator! = Clist.
Use of List
The use of the list must include the header file #include
1), how to define a list object
#include int main (void) { list }
2, using the member functions of the list push_back and Push_front inserts an element into the list
cList. push_back(‘a’); //把一个对象放到一个list的后面 cList. push_front (‘b’); //把一个对象放到一个list的前面
3, using the member function of list empty () to determine whether the list is empty
if (cList.empty()) { printf(“this list is empty”); }
4), using list
list for(c
1 vectorVector is equivalent to an arrayAllocate a continuous memory space in the memory for storage. Storage with no vector size specified is supported. During internal implementation of STL, a very large memory space is allocated for storage, that is, the size returned by the capacity () function, when the size of the allocated space is exceeded, a memory storage will be re-allocated. This gives us the feeling that the vector can be a continuous mem
STL containers can be grouped into the following broad categories:One: Sequence container, vector, list, deque, String.
II: Associated containers, with set, Multiset, map, Mulmap
Hash_set,hash_map, Hash_multiset, Hash_multimap
Third: Other miscellaneous: Stack, queue, Valarray, Bitset
Implementation of various containers of STL:
(1) VectorInternal data structure: array.Random access to each element, the t
1. Type Clock_t: it is a long type, used to record the number of clock timing units in a period of time, that is, the CPU running unit time.Size_t: defined in the Standard C library. It should be an unsigned int and a long unsigned int in a 64-bit system.Time_t: the number of seconds that have elapsed since 00:00:00, January 1, January 1, 1970 to this time point.Struct TM {Int tm_sec;/* Second-value range: [0, 59] */Int tm_min;/* minute-value range: [
random valuevoid Resize (size_type n,t x); Adjusts the elements of the list to N, multiple deletions, and a value of Xint size () const; Returns the number of elements in the current listint max_size () const; Returns the maximum allowable list element number value7) Other functions void swap (list x); Swapping elements from two listsvoid Splice (iterator it,list x); Link the list x to the current list iterator it points to the location where the list x becomes emptyvoid Splice (iterator it,li
vector element number valuesuch as: string str[7] = {"Has fun", "has fun", "Good Luck", "Good Luck", "has Fun", "has Fun", "has Fun"};VectorA.pop_back ();CoutCoutCoutProgram output:7) Other functionsvoid swap (vector); Exchange data for two vectors of the same typevoid assign (int n,const t x); Sets the value of the nth element in a vector to Xvoid Assign (Const_iterator first,const_iterator last); Sets the element in the vector [First,last] to the current vector element8) Common algorithms So
Instead of directly maintaining the controlled sequence, the container adapter implements all functions through the underlying container object stored in it.The queue class allows you to insert elements at the end of the underlying data structure, and also allows you to insert elements from the front (first in, first out).Include header file #include Common Queue operations:1.void push (const t val); Inserts an element at the end of the queue (implemented by invoking the Push_back function of th
controlled sequenceIterator Erase (iterator first,iterator last); Delete all elements within the range [First,last] in the controlled sequenceSize_type Erase (const key Key); Deletes an element with an element value equal to key and returns the number of deleted elementsvoid Clear (); Emptying the controlled sequence7) Other operation functions void swap (set x); Swap set elementsvoid swap (multiset x); Exchanging multiset elements Key_compare Key_comp () const; Returns a function for compari
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.