-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgorithm.cpp
35 lines (31 loc) · 916 Bytes
/
algorithm.cpp
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
33
34
35
#include <iostream>
#include <vector>
#include <algorithm> //for std::max - std::min - std::swap
template<typename T>
void bingo_sort(std::vector<T>& L) {
T minValue = *std::min_element(L.begin(), L.end());
T maxValue = *std::max_element(L.begin(), L.end());
T bingo = minValue;
T next_bingo = maxValue;
int nextIndex = 0;
while (bingo < maxValue) {
int startPosition = nextIndex;
for(int i = startPosition; i < L.size(); i++) {
if (L[i] == bingo) {
std::swap(L[i], L[nextIndex++]);
}
if (L[i] < next_bingo) {
next_bingo = L[i];
}
}
bingo = next_bingo;
next_bingo = maxValue;
}
}
int main() {
std::vector<int> numbers = {-1,1,4,2,5,3,2,1,1,2,2,2,4,5,5,5};
bingo_sort(numbers);
for (int x : numbers) {
std::cout << x << std::endl;
}
}