Save old files
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
#include <random>
|
||||
#include <vector>
|
||||
|
||||
#include "sorting.hpp"
|
||||
|
||||
template <typename Iter>
|
||||
void shuffling(Iter begin, Iter end) {
|
||||
static std::random_device rd;
|
||||
static std::mt19937 rng(rd());
|
||||
|
||||
for (auto cur = end - 1; cur > begin; -- cur) {
|
||||
int index = std::uniform_int_distribution<>(0, cur - begin)(rng);
|
||||
std::swap(*(begin + index), *cur);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Iter>
|
||||
void displaying(Iter begin, Iter end, int wrap) {
|
||||
const char* end_c = " \n";
|
||||
for (auto cur = begin; cur < end; ++ cur) {
|
||||
std::cout << *cur << end_c[((cur - begin + 1) % wrap) == 0];
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int length = 128;
|
||||
|
||||
if (argc > 1) {
|
||||
sscanf(argv[1], "%d", &length);
|
||||
}
|
||||
|
||||
std::vector<int> list(length);
|
||||
for (int i = 0; i < length; ++ i) {
|
||||
list.at(i) = i + 1;
|
||||
}
|
||||
|
||||
std::cout << "Raw: \n";
|
||||
displaying(list.begin(), list.end(), 16);
|
||||
|
||||
shuffling(list.begin(), list.end());
|
||||
std::cout << "Shuffle: \n";
|
||||
displaying(list.begin(), list.end(), 16);
|
||||
|
||||
isort(list.begin(), list.end());
|
||||
std::cout << "Sorted: \n";
|
||||
displaying(list.begin(), list.end(), 16);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user