Anonymous user
Sorting algorithms/Bogosort: Difference between revisions
→{{header|C++}}
(Add Swift) |
|||
Line 302:
=={{header|C++}}==
Uses C++11. Compile with
g++ -std=c++11 bogo.cpp
<lang cpp>#include <iterator>▼
<lang cpp>#include <algorithm>
#include <random>
/* Sorts anything that provides random access iterators. */
template<typename RAIterator> void bogo_sort(RAIterator begin,
RAIterator end) {
std::random_device rd;
std::mt19937 generator(rd());
}
}
▲#include <ext/algorithm>
int main() {
int a[] = {100, 2, 56, 200, -52, 3, 99, 33, 177, -199};
bogo_sort(std::begin(a), std::end(a));
copy(std::begin(a), std::end(a), std::ostream_iterator<int>(std::cout, " "));
▲ while (!__gnu_cxx::is_sorted(begin, end))
}</lang>
Output:
<pre>
-199 -52 2 3 33 56 99 100 177 200
</pre>
=={{header|C sharp|C#}}==
|