template <class InIter, class RandomIter> void partial_sort_copy( InIter xSrcFirst, InIter xSrcLast, RandomIter xDestFirst, RandomIter xDestLast );
#include <algorithm>
template <class InIter, class RandomIter, class BinaryPred> void partial_sort_copy( InIter xSrcFirst, InIter xSrcLast, RandomIter xDestFirst, RandomIter xDestLast, BinaryPred xComp );
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
using namespace std;
// Create two vector instances
vector<int> qV;
for (int i = 0; i < 20; i += 2) {
qV.push_back(20-i);
}
vector<int> qTarget(5);
vector<int>::iterator qIter;
// Output the vector
cout << "The Vector: ";
for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
cout << *qIter << " ";
}
cout << endl;
// Partial sort the vector
partial_sort_copy(qV.begin(), qV.end(), qTarget.begin(), qTarget.end());
// Output the resulting sorted vector
cout << "The Sorted Copy: ";
for (qIter = qTarget.begin(); qIter != qTarget.end(); ++qIter) {
cout << *qIter << " ";
}
cout << endl;
// Keep the window open
cin.get();
return 0;
}
© 20072025 XoaX.net LLC. All rights reserved.