visualization of bsort, manager now responsible for updates and time

split timeractions from timers into seperate header
integrated the experiments into an improved displaynumbers, which
includes the vector as well as bars above them
outsourced the calculation of delta time to the manager to clean up main()
This commit is contained in:
2026-07-17 00:04:28 +02:00
parent db8fc15560
commit 9dbc24efc1
5 changed files with 120 additions and 63 deletions
+53
View File
@@ -0,0 +1,53 @@
#include <vector>
#include "timer.hpp"
#include "timeractions.hpp"
#include <algorithm>
#include <chrono>
#include <cstddef>
#include <memory>
#include <ncurses.h>
#include <string>
#include <vector>
swapaction::swapaction(std::vector<int> &input_vector): input_vector(input_vector){}
void swapaction::update(const timer &input_timer){
if (!iscomplete) {
int temp = input_vector[it_i];
input_vector[it_i] = input_vector[input_vector.size() -1 - it_i];
input_vector[input_vector.size() - 1 - it_i] = temp;
it_i++;
if(it_i>=input_vector.size() / 2){iscomplete=true;}
}
}
sortaction::sortaction(std::vector<int> &input_vector): input_vector(input_vector) {}
//sorts the included array using bsort and external iterators rather than for loops
void sortaction::update(const timer &input_timer) {
if (!iscomplete) {
/**
we take a number, it_i loop
compare it with its neighbour, it_j loop
if it's larger swap it
keep going until it_i == length - sorted numbers
once that is true, reset it_j and advance it_i
**/
if (input_vector[it_j]>input_vector[it_j+1]) {
// int temp = input_vector[it_j + 1];
// input_vector[it_j + 1] = input_vector[it_j];
// input_vector[it_j] = temp;
std::swap(input_vector[it_j], input_vector[it_j+1]);
}
it_j++;
if (it_j >= input_vector.size() - 1 - it_i) {
it_j = 0;
it_i++;
}
if (it_i>=input_vector.size()) {
iscomplete=true;
}
}
}