-
Notifications
You must be signed in to change notification settings - Fork 0
/
SortingAlgorithms.cpp
30 lines (26 loc) · 1014 Bytes
/
SortingAlgorithms.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
#include "SortingAlgorithms.h"
void SortingAlgorithms::BubbleSort(Field &field, sf::RenderWindow &window, sf::Event& event) {
for(int i = 0; i < field.getColumns().size(); i++) {
window.clear();
for(int j = 0; j < field.getColumns().size() - 1 - i; j++) {
sf::Event event{};
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
if (field[j].value > field[j+1].value) {
std::swap(field[j], field[j+1]);
field.setColumnPosition(field[j]);
field.setColumnPosition(field[j+1]);
// field[j].cell.setFillColor(sf::Color::Red);
// field[j].cell.setFillColor(sf::Color::White);
} else {
continue;
}
}
std::this_thread::sleep_for(std::chrono::milliseconds (0));
field.drawAllColumns(window);
window.display();
}
}