mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
fix: use random_shuffle
`random_shuffle` was removed in C++17, however, we're using C++11 here, so there should be no harm.
This commit is contained in:
parent
2202ea1d67
commit
8cd0a77218
@ -10,7 +10,7 @@
|
|||||||
* biggest table size and hardest mode. The bigger the size, **the more letters are available**.
|
* biggest table size and hardest mode. The bigger the size, **the more letters are available**.
|
||||||
*
|
*
|
||||||
* @author [David Leal](https://github.com/Panquesito7)
|
* @author [David Leal](https://github.com/Panquesito7)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream> /// for IO operations
|
#include <iostream> /// for IO operations
|
||||||
#include <ctime> /// for std::time()
|
#include <ctime> /// for std::time()
|
||||||
@ -25,19 +25,6 @@
|
|||||||
#include <unistd.h> /// for sleep
|
#include <unistd.h> /// for sleep
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// `std::random_shuffle` was deprecated in C++14. To keep support with most compilers, we need to check the C++ version.
|
|
||||||
#if __cplusplus >= 201402L
|
|
||||||
template <typename T>
|
|
||||||
constexpr auto SHUFFLE(T a, T b) -> void {
|
|
||||||
return std::shuffle(a, b, std::mt19937(std::random_device()()));
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
template <typename T>
|
|
||||||
constexpr auto SHUFFLE(T a, T b) -> void {
|
|
||||||
return std::random_shuffle(a, b);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace
|
* @namespace
|
||||||
* @brief (Mini)game implementations.
|
* @brief (Mini)game implementations.
|
||||||
@ -95,7 +82,7 @@ void init(std::vector<T> *table) {
|
|||||||
pairs.push_back(letter);
|
pairs.push_back(letter);
|
||||||
}
|
}
|
||||||
|
|
||||||
SHUFFLE(pairs.begin(), pairs.end());
|
std::random_shuffle(pairs.begin(), pairs.end());
|
||||||
|
|
||||||
for (int i = 0; i < (*table).size(); i++) {
|
for (int i = 0; i < (*table).size(); i++) {
|
||||||
(*table)[i] = pairs[i];
|
(*table)[i] = pairs[i];
|
||||||
|
Loading…
Reference in New Issue
Block a user