Stl_ Algorithm _ Reversal (reverse,reverse_copy)

Source: Internet
Author: User

C + + Primer Learning:

Simple recording of My Learning process (code-based)


All containers apply


Reverse (b,e)//reversal interval data


Reverse_copy (B,E,B2)


/**------http://blog.csdn.net/u010579068------**/#include <iostream> #include <cstdio> #include < string> #include <vector> #include <list> #include <deque> #include <algorithm>using namespace std;/*****************************************//all containers for reverse (b,e)//reversal interval data reverse_copy (B,E,B2) ******* **********************************//**------------------------------------------------------------------------- ---------STL Algorithm-Variable Order algorithm reverse ()//reversal reverse_copy () rotate ()//Rotation rotate_copy () next_permutation () Prev_pe Rmutation () random_shuffle () partition () stable_partition ()------------------------------------------------------ ----------------------------**//******************************************************************************* Std::reverse all sort containers for algorithm--------------------------------------- -----------------------------------------------<algorithm>template <class bidirectionaliterator> void Reverse (bidirectionaliterator first, Bidirectionaliterator last);//eg:template <class bidirectionaliterator> void Reverse (bidirectionaliterator first, Bidirectionaliterator last) {while ((First!=last) && (First!=--last)) swap (*first++,*last);} *************************************************************************************//************************                        Std::reverse_copy All sort containers apply Algorithm--------------------------------------------------------------------------------------template <                                Class Bidirectionaliterator, Class outputiterator> Outputiterator reverse_copy (bidirectionaliterator First, Bidirectionaliterator last, outputiterator result);//eg:template <class Bidirectionaliterator, Class outputiterator> Outputiterator reverse_copy (bidirectionaliterator first, BidireCtionaliterator last, outputiterator result) {while (first!=last) *result++ = *--last; return result;} /int Main () {Vector<int    > myvector;    Vector<int>::iterator it; Set some values:for (int i=1; i<10; ++i) Myvector.push_back (i);       123456789reverse(myvector.begin(),myvector.end());    9 8 7 6 5 4 3 2 1//Print out Content:cout << "myvector contains:";    For (It=myvector.begin (); It!=myvector.end (); ++it) cout << "" << *it;     cout << Endl;  int myints[] = {n/a}; cout << "the 3!  Possible permutations with 3 elements:\n ";  Sort (myints,myints+3);  Reverse (myints,myints+3);  Do {cout << myints[0] << "<< myints[1] <<" "<< myints[2] << Endl;    } while (Prev_permutation (myints,myints+3)); /**-------------------------------------------------------------------------------------**///int myints[] = {1,2,3,4,5,6,7,8,9};    Deque<int> Mydeque;    Deque<int>::iterator IQ;    Mydeque.resize (9);    Reverse_copy (Myvector.begin (), Myvector.end (), Mydeque.begin ());    Print out Content:cout << "mydeque contains:";    For (Iq=mydeque.begin (); Iq!=mydeque.end (); ++iq) cout << "" << *iq;    cout << Endl; return 0;}


Stl_ Algorithm _ Reversal (reverse,reverse_copy)

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.