Stl_ Algorithm _ Local ordering (Partial_sort, partial_sort_copy)

Source: Internet
Author: User

C + + Primer learning.

Simple recording of My Learning process (code-based)


/*****************************************
//
Partial_sort (b,se,e)
Partial_sort (b,se,e,p)
Partial_sort_copy (sb,se,db,de)
Partial_sort_copy (sb,se,db,de,p)
************** /
/**---------------------------------------------------------------------------- ------
STL Algorithm---Sorting algorithm
sort ()                  make_heap ()
Stable_ Sort ()           push_heap ()
Partial_sort ()          pop_heap ()
P Artial_sort_copy ()     sort_heap ()
nth_element ()
partition ()
Stable_partition ()
----------- -----------------------------------------------------------------------**/


/**------http://blog.csdn.net/u010579068------**/#include <iostream> #include <cstdio> #include < string> #include <vector> #include <list> #include <deque> #include <algorithm>using Namespace Std;/*****************************************//partial_sort (b,se,e) partial_sort (b,se,e,p) Partial_ Sort_copy (Sb,se,db,de) partial_sort_copy (sb,se,db,de,p) *****************************************//**----------- -----------------------------------------------------------------------STL Algorithm---Sorting algorithm sort () make_heap () Stab Le_sort () push_heap () Partial_sort () pop_heap () partial_sort_copy () sort_heap () nth_element () partition () stable_partition ()----------------------------------------------------------------------------------**//**** std::p artial_sort All sort capacity For algorithm--------------------------------------------------------------------------------------template <class randomaccessiterator> void Partial_sort (Randomaccessiterator first, Randomaccessiterator Middle, randomaccessiterator last); template <class Randomaccessiterator, CLA ss compare> void Partial_sort (randomaccessiterator first, randomaccessiterator middle, Randomac Cessiterator last, Compare comp);//eg:*************************************************************************** std::p Artial_ Sort_copy all sort containers for algorithm----------------------------------------------------------    ----------------------------Template <class Inputiterator, class randomaccessiterator> Randomaccessiterator                        Partial_sort_copy (Inputiterator first,inputiterator last, Randomaccessiterator Result_first, Randomaccessiterator Result_last ); template <class Inputiterator, class Randomaccessiterator, class compare> Randomaccessiterator Partial_sort_c                        Opy (Inputiterator first,inputiterator last, Randomaccessiterator Result_first, Randomaccessiterator Result_last, Compare comp);//eg:************************************************************ /bool myfunction (int i,int j) {return (I&LT;J);}    Template <typename t>void Print (t& V) {typename t::iterator iter=v.begin ();    while (iter! = V.end ()) {cout<<*iter++<< ""; } Cout<<endl;}    int main () {int myints[] = {7,6,9,4,1,5,8,2,3};    Vector<int> Myvector (myints, myints+9);//Vector<int>::iterator it;    Using default comparison (operator <): Partial_sort (Myvector.begin (), Myvector.begin () +5, Myvector.end ());    cout << "myvector contains:";    Print (Myvector);    Deque<int> Mydeque (myints,myints+9); Using function as Comp Partial_sort (Mydeque.begin (), Mydeque.begin () +5, Mydeque.end (), myfunction);    Print out Content:cout << "mydeque contains:";    Print (Mydeque);//For (It=myvector.begin (); It!=myvector.end (); ++it)//cout << "" << *it;    cout << Endl;    /**--------------------------------------------------------------------------**/vector<int> VEC (5);    Deque <int> DEQ (5);    Using default comparison (operator <): Partial_sort_copy (myints, Myints+9, Vec.begin (), Vec.end ());    cout << "myvector contains:";    Print (VEC);    Using function as Comp partial_sort_copy (myints, Myints+9, Deq.begin (), Deq.end (), myfunction);    Print out Content:cout << "mydeque contains:";    Print (DEQ);//For (It=myvector.begin (); It!=myvector.end (); ++it)//cout << "" << *it;    cout << Endl; return 0;}


Stl_ Algorithm _ Local ordering (Partial_sort, partial_sort_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.