Difference between revisions of "CPP/STL/RandomShuffle"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) (Created page with '==RandomShuffle.cpp== <source lang="cpp"> #include <iostream> #include <algorithm> #include <vector> int main(int argc, char* argv[]) { std::vector<int> v; //add 10 integ…') |
Daviddoria (Talk | contribs) |
||
| Line 31: | Line 31: | ||
return 0; | return 0; | ||
} | } | ||
| + | |||
| + | </source> | ||
| + | |||
| + | ==CMakeLists.txt== | ||
| + | <source lang="cmake"> | ||
| + | cmake_minimum_required(VERSION 2.6) | ||
| + | |||
| + | Project(RandomShuffle) | ||
| + | ADD_EXECUTABLE(RandomShuffle RandomShuffle.cpp) | ||
</source> | </source> | ||
Latest revision as of 08:20, 26 February 2011
RandomShuffle.cpp
#include <iostream> #include <algorithm> #include <vector> int main(int argc, char* argv[]) { std::vector<int> v; //add 10 integers (0 to 9) for(int i = 0; i < 10; i++) { v.push_back(i); } std::cout << "Ordered" << std::endl; for(int i = 0; i < 10; i++) { std::cout << v[i] << " "; } std::random_shuffle(v.begin(), v.end()); std::cout << std::endl << "Shuffled" << std::endl; for(int i = 0; i < 10; i++) { std::cout << v[i] << " "; } return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) Project(RandomShuffle) ADD_EXECUTABLE(RandomShuffle RandomShuffle.cpp)