| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #include <vector>
- #include "timer.hpp"
- #include "timeractions.hpp"
- #include <algorithm>
- #include <ncurses.h>
- #include <vector>
- SwapAction::SwapAction(std::vector<int> &input_vector): input_vector(input_vector){}
- void SwapAction::update(const Timer &input_timer){
- if (!is_complete) {
- 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){is_complete=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 (!is_complete) {
- /**
- 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()) {
- is_complete=true;
- }
- }
- }
|