diff --git a/include/collections.hpp b/include/collections.hpp index 98caacb..11e170e 100644 --- a/include/collections.hpp +++ b/include/collections.hpp @@ -122,12 +122,11 @@ struct linked_list next->first = this; return *next; } - next->put(val); if (first) next->first = first; else next->first = this; - return *next; + return next->put(val); } size_t depth() diff --git a/src/LuaSortList.hpp b/src/LuaSortList.hpp index ee2f44a..5fc6255 100644 --- a/src/LuaSortList.hpp +++ b/src/LuaSortList.hpp @@ -23,7 +23,7 @@ public: bool sorted() const { - for (int i = 1; i < list.size() + 1; ++i) + for (int i = 1; i < list.size(); ++i) { if (list[i - 1] > list[i]) return false; } diff --git a/src/main.cpp b/src/main.cpp index 52f1190..3fb7b8d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ #include #include "sortiva/sortiva.hpp" -#undef _DEBUG +//#undef _DEBUG int main(int argc, char** argv) { printf("Darling, I'm Home!\n"); diff --git a/src/sortiva/sortiva-draw.cpp b/src/sortiva/sortiva-draw.cpp index 83e81c9..f8c6ba4 100644 --- a/src/sortiva/sortiva-draw.cpp +++ b/src/sortiva/sortiva-draw.cpp @@ -82,12 +82,12 @@ void Sortiva::draw() int g = plane.height / static_cast(cvals + 1); int h = (plane.height - static_cast(cvals - 1) * g) / 2; int e = w / 2; - + float wf = static_cast(w); float pwhd = sqrtf(plane.width * plane.width + plane.height * plane.height); float pw = plane.width / pwhd - 0.01f; float ph = plane.height / pwhd; - float l = pw * ph * pwhd * 0.02f; + float l = pw * ph * pwhd * 0.02f - static_cast(steps) / 2; // Make more fitting for (size_t i = 0; i < steps; ++i) { @@ -119,7 +119,7 @@ void Sortiva::draw() Color col = sorter_colors[(v * colid) % sorter_colors_size]; - float wf = static_cast(w); + int s = 0; for (; list->next; list = list->next) @@ -177,7 +177,7 @@ void Sortiva::draw() ); if (list->first) - list = list->first->next; + list = list->first; value = list->value; pos = { wf - e + plane.x, h + (value - 1) * g + plane.y }; diff --git a/src/sortiva/sortiva.cpp b/src/sortiva/sortiva.cpp index 4df4ea5..b0cc0eb 100644 --- a/src/sortiva/sortiva.cpp +++ b/src/sortiva/sortiva.cpp @@ -64,6 +64,7 @@ void Sortiva::setup() for (int i = 1; i <= count; ++i) // 1,2,3,4,5 { m_List.list.push_back(i); + m_Steps->emplace_back(); } std::random_device dev; @@ -73,6 +74,6 @@ void Sortiva::setup() for (int i = 1; i <= count; ++i) { - m_Steps->emplace_back().value = m_List.list[i - 1]; + m_Steps->at(m_List.at(i-1) - 1).value = i; } } diff --git a/src/sortiva/sortiva.hpp b/src/sortiva/sortiva.hpp index fbc6c34..55e00dd 100644 --- a/src/sortiva/sortiva.hpp +++ b/src/sortiva/sortiva.hpp @@ -11,7 +11,7 @@ class Bubble_Sorter : Future LuaSortList* list = nullptr; struct STATE { - size_t n = 0; + size_t n = 1; } state; public: Bubble_Sorter() = default; @@ -19,20 +19,20 @@ public: bool poll() override { - int n = list->size(); + size_t n = list->size(); if (n <= 1) { return true; } state.n = state.n + 1; - if (state.n >= n) + if (state.n > n) { - state.n = 1; + state.n = 2; } - if (list->at(state.n - 1) > list->at(state.n)) { - list->swap(state.n - 1, state.n); + if (list->at(state.n - 2) > list->at(state.n - 1)) { + list->swap(state.n - 2, state.n - 1); return false; } return list->sorted();