template <class BidirIter> void stable_sort( BidirIter xFirst, BidirIter xLast );
#include <algorithm>
template <class BidirIter, class Pred> void stable_sort( BidirIter xFirst, BidirIter xLast, Pred xComp );
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
using namespace std;
// Create a vector with random entries
vector<int> qV;
for (int i = 0; i < 10; ++i) {
qV.push_back(rand() % 20);
}
// Output the original randomized vector
vector<int>::iterator qIter;
cout << "Random Vector: ";
for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
cout << *qIter << " ";
}
cout << endl;
// Sort the vector
stable_sort(qV.begin(), qV.end());
// Output the sorted vector
cout << "Sorted Vector: ";
for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
cout << *qIter << " ";
}
cout << endl;
// Keep the window open
cin.get();
return 0;
}
© 20072025 XoaX.net LLC. All rights reserved.