template <class RandomIter> void sort( RandomIter xFirst, RandomIter xLast );
#include <algorithm>
template <class RandomIter, class Pred> void sort( RandomIter xFirst, RandomIter 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 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; }
© 20072024 XoaX.net LLC. All rights reserved.