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)