STL Modification Algorithm __ Algorithm

Source: Internet
Author: User
Tags comparison sort

Modify algorithm:

Algorithm Usage Description
Copy Outit copy (InIt first,init last,outit x); Copy the elements between [first,last] to the location specified by x
Copy_backward BidIt2 Copy_backward (BidIt1 first,bidit1 last,bidit2 x); Copy elements between [First,last] to the front of the x specified position
Fill void Fill (Fwdit first,fwdit last,const t& x); Fills the section between [First,last] with element x
Fill_n void Fill_n (Outit, Size n,const t& x); To populate a container with n elements x from first
Generate void Generate (Fwdit first,fwdit last, Gen g); Call function g () to populate elements between [first,last)
Generate_n void Generate_n (Outit first,size N, Gen g); Call function g () to populate n elements from first
Remove Fwdit Remove (fwdit first,fwdit last,const t& val); Removes the element Val from [First,last) and returns the position after the last element in the new zone
Remove_if Fwdit remove_if (Fwdit first,fwdit last, Pred PR); Remove from [first,last] all elements that enable PR to return true, and return to the location of the last element between the new zone
Remove_copy Outit remove_copy (InIt first,init last,outit x,const t& val); Removes the element Val from [first,last) and copies the remaining elements to the beginning of the X interval, returning the position of the last element being copied
Remover_copy_if Outit remove_copy_if (InIt first,init last,outit x,pred PR); Remove from [first,last) all elements that enable PR to return true, and copy the remaining elements to the beginning of the X space, returning the position of the last element being copied
Replace void replace (Fwdit first,fwdit last,const t& vold,const t&); Replace all elements in [first,last] with vnew with Vold
Replace_if void Replace_if (Fwdit first,fwdit last,pred pr,const t& val); Replace all elements in [First,last] with Val that can return true to function pr
Replace_copy Outit replace_copy (InIt first,init last,outit x,const t&, Vold,const t&); Copy all elements in [first,last] to a space starting with X, and if there are elements in the copied element that have a value of vold, replace with Vnew and return to the last position of the final element copied to the target container
Replace_copy_if Outit replace_copy_if (InIt first,init last,outit x,pred pr,const t& val); Copy all elements in [first,last] to a space starting with X, and if there are elements in the copied element that can return true to the function PR, replace them with Vnew, and return to the last position of the final element copied to the target container.
Swap void swap (Container &c1,container &c2); Exchange container C1 and C2 elements
Iter_swap void Iter_swap (FwdIt1 x,fwdit2 y); Exchange iterator X,y The value of the element being referred to
Swap_ranges FwdIt2 swap_ranges (FwdIt1 first,fwdit1 last,fwdit2 x); With all elements of the contiguous element exchange interval [First,last] Starting with X, returns the next position of the last element in the second interval
Sort void sort (Ranit-I, ranit last);
void sort (Ranit, Ranit last, Pred PR);
The elements in the interval [first,last] are sorted in ascending order, and the second form PR is used to set the comparison function
Merge Outit merge (InIt1 first1,init1 last1,init2 first2,init2 last2,outit x);
Outit merge (InIt1 first1,init1 last1,init2 first2,init2 last2,outit x, Pred PR);
Merges two ordered intervals [first1,last1) and [First2,last2] and stores the merged elements in the container where the x begins, and the second form PR (ELEM1,ELEM2) Specifies the comparison rule
Inplace_merge void Inplace_merge (BidIt, BidIt Middle, bidit last);
void Inplace_merge (BidIt, BidIt Middle, BidIt last, Pred PR);
Merge intervals [first,middle) and [Middle,last], and store the merged elements in the first start interval, the second form PR (ELEM1,ELEM2) Specifies the comparison rule
Reverse void reverse (BidIt, BidIt last); Invert the order of elements in the interval [first,last]
Reverse_copy Outit reverse_copy (BidIt, BidIt last,outit x); Copy the elements of the interval [first,last] to the X start interval, resulting in the order of the elements of the copy, the source range not modified, and the next position of the last element copied to the target range.
Rotate void rotate (Fwdit first,fwdit middle,fwdit last); element positions for swap intervals [first,middle) and [Middle,last]
Rotate_copy Outit rotate_copy (fwdit first,fwdit middle,fwdit last,outit x); Copy the elements of the interval [first,last] to the beginning of the X container, the position of the exchange [First,middle] and [Middle,last) at the time of the copy, and the source range does not change, returning the next of the last element copied to the target range
Random_shuffle void Random_shuffle (Ranit, Ranit last);
void Random_shuffle (Ranit, Ranit last, fun& f);
Random ordering of elements on the interval [first,last], F for specifying the sort function
Transform Outit transform (InIt first,init last,outit x, Unop UOP); Performs a UOP (Elem) operation on all elements on the interval [first,last], and the result is placed in an interval beginning with X, returning the next of the last element copied to the target end
Transform Outit transform (InIt1 first1,init1 last1,init2 first2,outit x, Binop bop); Perform a two-dollar Operation Bop (ELEM1,ELEM2) on the elements of the interval [first1,last1) and the element starting at First2, and the result is placed in the interval beginning with X, returning the next of the last element copied to the target end.
Set_itersection Outit set_intersection (InIt1 first1,init1 last1,init2 first2,init2 x);
Outit set_intersection (InIt1 first1,init1 last1,init2 first2,init2 last2,outit x, Pred PR);
The intersection of two intervals [First1,last1), [First2,last2], is stored in the container at the beginning of the X, the source interval element is not modified, PR is used to specify the operation function, and the next position of the last element copied to the target range is returned.
Set_union Outit set_union (InIt1 first1,init1 last1,init2 first2,init2 x);
Outit set_union (InIt1 first1,init1 last1,init2 first2,init2 last2,outit x, Pred PR);
two intervals [First1,last1), [First2,last2] of the set, stored in the beginning of the X container, the source interval element is not modified, PR is used to specify the operation function, return the copy to the target range of the last element of the next
Set_difference Outit set_difference (InIt1 first1,init1 last1,init2 first2,init2 x);
Outit set_difference (InIt1 first1,init1 last1,init2 first2,init2 last2,outit x, Pred PR);
For two sets [First1,last1], [first2,last2) of the difference set, stored in the beginning of the X container, the source interval element has not been modified, PR is used to specify the operation function, return copy to the target range of the last element of the next position
Set_symmetric_

Difference

Outit set_symmetric_difference (InIt1 first1,init1 last1,init2 first2,init2 x);
Outit set_symmetric_difference (InIt1 first1,init1 last1,init2 first2,init2 last2,outit x, Pred PR);
The symmetric difference (i.e. (a-b) + (B-A)) of the set [First1,last1], [First2,last2], is stored in the container at the beginning of the X, the source interval element is not modified, PR is used to specify the operation function, and the next position of the last element in the target range is returned.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.