The C + + list function is detailed
First of all, how to debug under the Eclipse tool: You have to set a breakpoint, and then start your application in debug mode, do not run, when the program runs to your breakpoint location will stop, you will be prompted to enter the Debug view mode of operation, F5 is entered into the inside of a function or statement block, F6 is a single step, a line of walking, F7 can jump the current listener function or statement block F8 will jump directly to the next breakpoint.
Enter the following topics:
First, construct, destructor,= operator
1, function: Declare the list container. 4 different ways
List<int> first; Empty list of INTs
list<int> second (4,100); Four ints with value 100. 4 x
List<int> third (Second.begin (), Second.end ()); Iterating through second
List<int> fourth (third); A copy of third
2, Function: Logout list. ~list ();
3, prototype:list1 = List2;
Function: assigns list2 to List1, including all elements of list and size of List2
Return value: Thispointer
Second, return the function of the iterator class
Begin,end,rbegin,rend
Example:
Begin points to the first element, a yellow arrow. End is the last position of the element, the black arrow. begin and end are used together, and the list is output in positive order . Rbegin refers to the first element in reverse order, that is, the last element, the blue arrow. rend refers to the previous position of the last element in reverse order, which is the previous position of the first element, and the red arrow.
Rbegin and rend are generally used together to output lists in reverse order .
Third,the capacity-related functions of the list
1,empty
Prototype:bool Empty () const;
Function: Determine If Lsit is empty, that is, if size is 0
Return value:size is 0, returns true, otherwise, false
2.size
Prototype:size_type size () const;
Function: Returns the number of elements in the Lsit
return value:size_type
3,max_size
Prototype:size_type max_size () const;
Function: Returns the maximum capacity of the lsit
return value:
4,resize
Prototype:void Resize (size_type sz, t C = t ());
Function: Reassign the size of the lsit. If sz is smaller than the current size, the excess value is removed, and if sz is larger than the current size, the capacity is increased and filled with C. For example:
Mylist.resize (5); Set size to 5
Mylist.resize (8,100); The size is set to 8, and the extra is filled with 100
Mylist.resize (12); Set size to
Iv. acquiring elements
1,front
Prototype: reference Front ();
Const_reference Front () const;
Function: Gets the first element
Return value: The value of the first element
2. Back
Prototype:reference back ();
Const_reference back () const
Function: Gets the last element
Return value: Last element
V. Modifying the function of Lsit
1,assign
Prototype:void Assign (Inputiterator first, Inputiterator last);
void Assign (size_type n, const t& u)
Function: Reassign the space to the list and assign a value. assign a value in the [First,last] range or a copy of N-Times U value to the list
return value: None
2. Push_front: Inserts an element from the beginning. Pop_front: Delete First element
push_back: Inserts an element at the tail. pop_back: Delete last element
3.Insert
Prototype:iterator insert (iterator position, const t& x);
void Insert (iterator position, Size_type N, const t& x);
Template <class inputiterator>
void Insert (iterator position, Inputiterator first, Inputiterator last);
Features: inserting elements
Insert (iterator position, const t& x): insert element x at position position
Insert (iterator position, Size_type N, const t& x): starts inserting n x at position position
Insert (iterator position, Inputiterator first, Inputiterator last): start insertion at position position
the element within the range [first, last].
Return value: Only the first function returns the location of the inserted element
4,Erase
Prototype:iterator erase (iterator position);
Iterator Erase (iterator first, iterator last);
Function: Clears the elements in the position or [First,last] range of the linked list. the size value of the list is reduced .
Return value: The next position of the last element cleared (iterator )
5.Swap
Prototype:void Swap (list<t,allocator>& lst)
Function: swap two lsit
6.Clear
Function: Empty list
Vi. functions of the Operation class
1,splice
Prototype: Set List2 to call the splice function
void Splice (iterator position, list<t,allocator>& x); inserts all elements from list X into the list2 of the position where the function is called . The List x will be emptied.
void Splice (iterator position, list<t,allocator>& X, iterator i); inserts the element in X that points to i into the list2 Position place. x removes the value at the I position.
void Splice (iterator position, list<t,allocator>& X, iterator first, iterator last); Inserts the element at the [first,last] position in X at the position of the List2 .
function:Move elements from list to list. Move the value in one lsit to another list
2.Remove
Prototype:void Remove (const t& value);
Function: Clears the specified value in the list , andthe size of the lsit is reduced accordingly.
return value: None
3,remove_if
Prototype:template <class predicate>
void remove_if (predicate pred);
Function: Removes the element when it satisfies predicate pred to return a true value. pred can be a function that returns a bool type, or it can be a class that overrides the operator function. For example:
A predicate implemented as a function:
BOOL Single_digit (const int& value) {return (VALUE<10);}
A predicate implemented as a class:
Class Is_odd
{
Public
BOOL Operator () (const int& value) {return (value%2) ==1;}
};
return value: None
4.Unique
Prototype:void Unique ();
Template <class binarypredicate>
void Unique (Binarypredicate binary_pred); de- duplicated values are binary_pred by rule. For example:
BOOL Same_integral_part (double first, double second)
{return (int (first) ==int (second));}
A binary predicate implemented as a class:
Class Is_near
{
Public
BOOL operator () (double first, double second)
{return (Fabs (First-second) <5.0);}
};
Call:Mylist.unique (Same_integral_part);
Mylist.unique (Is_near ());
function: Eliminate duplicate elements in list
return value:
5.Merge
Prototype:void Merge (list<t,allocator>& x);
Template <class compare>
void merge (list<t,allocator>& x, Compare comp);
Function: Merges two lists that have been ordered (both ascending and descending) .
Merge () combines two well-ordered tables. If a table is not sorted, themerge () can still produce a table that contains the set of the original two table elements. Of course, there is no guarantee that the results will be sorted. As with the splice () function, themerge () function does not copy elements.
The function of the merge function is to combine two ordered sequences into an ordered sequence. Function parameters:merge (First1,last1,first2,last2,result,compare),//firs1t as the first iterator,Last1 as the last iterator of the first container, First2 is the first iterator to the second container,Last2 is the end iterator of the container, resultis the container that holds the result,Comapre is the comparison function (can be slightly written, and the default is to merge into an ascending sequence).
return value:
6.Sort
Prototype:void sort ();
Template <class compare>
void sort (Compare comp);
Function: Sort
return value:
7,reverse
Function: resets the elements in the list to the reverse.
return value:
C + + List container Series functional functions Detailed