-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathStupidSorting.cpp
More file actions
32 lines (26 loc) · 843 Bytes
/
Copy pathStupidSorting.cpp
File metadata and controls
32 lines (26 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <vector>
#include <iostream>
template <typename Collection, typename Comparator, typename = typename Collection::iterator>
void stupid_sorting(Collection& collection, Comparator comparator) noexcept
{
for (int i = 0; i < static_cast<int>(collection.size() - 1); ++i)
{
if (comparator(collection[i], collection[i + 1]))
{
std::swap(collection[i], collection[i + 1]);
i = -1;
}
}
}
int main()
{
std::vector<int> vector = { 7, 9, 1, 5, 8, 1, 8, 3, 7, 3 };
std::cout << "Not sorted array: ";
for (const auto& value : vector)
std::cout << value << " ";
stupid_sorting(vector, [](int a, int b) { return a < b; });
std::cout << "\nSorted array: ";
for (const auto& value : vector)
std::cout << value << " ";
return EXIT_SUCCESS;
}