mirror of
https://github.com/koloideal/SortLab.git
synced 2026-06-10 10:25:30 +03:00
update
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "Sorter.hpp"
|
||||
|
||||
class BubbleSorter : public Sorter {
|
||||
public:
|
||||
BubbleSorter();
|
||||
|
||||
void step(Array& array) override;
|
||||
bool isFinished() const override;
|
||||
std::string getName() const override;
|
||||
void reset() override;
|
||||
|
||||
private:
|
||||
enum class Phase { COMPARING, SWAPPING, NEXT };
|
||||
|
||||
int i_;
|
||||
int j_;
|
||||
int n_;
|
||||
bool finished_;
|
||||
Phase phase_;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "Sorter.hpp"
|
||||
|
||||
class InsertionSorter : public Sorter {
|
||||
public:
|
||||
InsertionSorter();
|
||||
|
||||
void step(Array& array) override;
|
||||
bool isFinished() const override;
|
||||
std::string getName() const override;
|
||||
void reset() override;
|
||||
|
||||
private:
|
||||
enum class Phase { COMPARING, SHIFTING, INSERTING, NEXT };
|
||||
|
||||
int i_;
|
||||
int j_;
|
||||
int n_;
|
||||
float key_;
|
||||
bool finished_;
|
||||
Phase phase_;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include "Sorter.hpp"
|
||||
#include <vector>
|
||||
|
||||
class MergeSorter : public Sorter {
|
||||
public:
|
||||
MergeSorter();
|
||||
|
||||
void step(Array& array) override;
|
||||
bool isFinished() const override;
|
||||
std::string getName() const override;
|
||||
void reset() override;
|
||||
|
||||
private:
|
||||
enum class Phase { MERGING, COPYING_LEFT, COPYING_RIGHT, COPYING_BACK, NEXT_MERGE };
|
||||
|
||||
int currentSize_;
|
||||
int leftStart_;
|
||||
int mid_;
|
||||
int rightEnd_;
|
||||
int leftIndex_;
|
||||
int rightIndex_;
|
||||
int mergeIndex_;
|
||||
std::vector<float> temp_;
|
||||
bool finished_;
|
||||
Phase phase_;
|
||||
int n_;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include "Sorter.hpp"
|
||||
#include <vector>
|
||||
|
||||
class QuickSorter : public Sorter {
|
||||
public:
|
||||
QuickSorter();
|
||||
|
||||
void step(Array& array) override;
|
||||
bool isFinished() const override;
|
||||
std::string getName() const override;
|
||||
void reset() override;
|
||||
|
||||
private:
|
||||
enum class Phase { PARTITIONING, SWAPPING_PIVOT, PUSHING_RANGES };
|
||||
|
||||
struct Range {
|
||||
int low;
|
||||
int high;
|
||||
};
|
||||
|
||||
std::vector<Range> stack_;
|
||||
int currentLow_;
|
||||
int currentHigh_;
|
||||
int pivotIndex_;
|
||||
int i_;
|
||||
int j_;
|
||||
float pivotValue_;
|
||||
bool finished_;
|
||||
Phase phase_;
|
||||
int n_;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "Sorter.hpp"
|
||||
|
||||
class SelectionSorter : public Sorter {
|
||||
public:
|
||||
SelectionSorter();
|
||||
|
||||
void step(Array& array) override;
|
||||
bool isFinished() const override;
|
||||
std::string getName() const override;
|
||||
void reset() override;
|
||||
|
||||
private:
|
||||
enum class Phase { FINDING_MIN, SWAPPING, NEXT };
|
||||
|
||||
int i_;
|
||||
int j_;
|
||||
int minIndex_;
|
||||
int n_;
|
||||
bool finished_;
|
||||
Phase phase_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user