fixing errors, making cuts

This commit is contained in:
noffie 2025-01-11 03:59:50 +01:00
parent 54703852e7
commit 2515509e55
6 changed files with 15 additions and 15 deletions

View file

@ -122,12 +122,11 @@ struct linked_list
next->first = this; next->first = this;
return *next; return *next;
} }
next->put(val);
if (first) if (first)
next->first = first; next->first = first;
else else
next->first = this; next->first = this;
return *next; return next->put(val);
} }
size_t depth() size_t depth()

View file

@ -23,7 +23,7 @@ public:
bool sorted() const 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; if (list[i - 1] > list[i]) return false;
} }

View file

@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include "sortiva/sortiva.hpp" #include "sortiva/sortiva.hpp"
#undef _DEBUG //#undef _DEBUG
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
printf("Darling, I'm Home!\n"); printf("Darling, I'm Home!\n");

View file

@ -82,12 +82,12 @@ void Sortiva::draw()
int g = plane.height / static_cast<float>(cvals + 1); int g = plane.height / static_cast<float>(cvals + 1);
int h = (plane.height - static_cast<float>(cvals - 1) * g) / 2; int h = (plane.height - static_cast<float>(cvals - 1) * g) / 2;
int e = w / 2; int e = w / 2;
float wf = static_cast<float>(w);
float pwhd = sqrtf(plane.width * plane.width + plane.height * plane.height); float pwhd = sqrtf(plane.width * plane.width + plane.height * plane.height);
float pw = plane.width / pwhd - 0.01f; float pw = plane.width / pwhd - 0.01f;
float ph = plane.height / pwhd; float ph = plane.height / pwhd;
float l = pw * ph * pwhd * 0.02f; float l = pw * ph * pwhd * 0.02f - static_cast<float>(steps) / 2; // Make more fitting
for (size_t i = 0; i < steps; ++i) for (size_t i = 0; i < steps; ++i)
{ {
@ -119,7 +119,7 @@ void Sortiva::draw()
Color col = sorter_colors[(v * colid) % sorter_colors_size]; Color col = sorter_colors[(v * colid) % sorter_colors_size];
float wf = static_cast<float>(w);
int s = 0; int s = 0;
for (; list->next; list = list->next) for (; list->next; list = list->next)
@ -177,7 +177,7 @@ void Sortiva::draw()
); );
if (list->first) if (list->first)
list = list->first->next; list = list->first;
value = list->value; value = list->value;
pos = { wf - e + plane.x, h + (value - 1) * g + plane.y }; pos = { wf - e + plane.x, h + (value - 1) * g + plane.y };

View file

@ -64,6 +64,7 @@ void Sortiva::setup()
for (int i = 1; i <= count; ++i) // 1,2,3,4,5 for (int i = 1; i <= count; ++i) // 1,2,3,4,5
{ {
m_List.list.push_back(i); m_List.list.push_back(i);
m_Steps->emplace_back();
} }
std::random_device dev; std::random_device dev;
@ -73,6 +74,6 @@ void Sortiva::setup()
for (int i = 1; i <= count; ++i) 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;
} }
} }

View file

@ -11,7 +11,7 @@ class Bubble_Sorter : Future<LuaSortList>
LuaSortList* list = nullptr; LuaSortList* list = nullptr;
struct STATE struct STATE
{ {
size_t n = 0; size_t n = 1;
} state; } state;
public: public:
Bubble_Sorter() = default; Bubble_Sorter() = default;
@ -19,20 +19,20 @@ public:
bool poll() override bool poll() override
{ {
int n = list->size(); size_t n = list->size();
if (n <= 1) { if (n <= 1) {
return true; return true;
} }
state.n = state.n + 1; 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)) { if (list->at(state.n - 2) > list->at(state.n - 1)) {
list->swap(state.n - 1, state.n); list->swap(state.n - 2, state.n - 1);
return false; return false;
} }
return list->sorted(); return list->sorted();