主要函数 template<class RandIt> void random_shuffle(RanIt first, RanIt last) template<class RandIt first, RanIt last, Fun & f> 例子 #include <iostream> #include <algorithm> #include <vector> #include <iterator> using namespace std; int main(int argc, char *argv[]) { int a[] = {1, 2, 3, 4, 5}; float b[] = {1.1f, 2.1f, 3.1f, 4.1f, 5.1f}; char c[] = {'a', 'b', 'c', 'd', 'e'}; cout << "原始数据 a[] = "; copy(a, a+5, ostream_iterator<int>(cout, " ")); cout << endl; random_shuffle(a, a+5); cout << "random_shuffle后"; copy(a, a+5, ostream_iterator<int>(cout, " ")); cout << endl; cout << "原始 b = []"; copy(b, b+5, ostream_iterator<float>(cout, " ")); cout << endl; cout << "rand_shuffle后:"; random_shuffle(b, b+5); copy(b, b+5, ostream_iterator<float>(cout, " ")); cout << endl; cout << "原始: c[] ="; copy(c, c+5, ostream_iterator<char>(cout, " ")); cout << endl; cout << "random_shufle后:"; random_shuffle(c, c+5); copy(c, c+5, ostream_iterator<char>(cout, " ")); cout << endl; system("pause"); return 0; }