<tb@panthema.net>
<http://www.gnu.org/licenses/>
#ifndef SORTALGO_H
#define SORTALGO_H
#include <wx/string.h>
#include "WSortView.h"
struct AlgoEntry
{
wxString name;
void (*func)(class WSortView&);
unsigned int inversion_count_limit;
wxString text;
};
extern const struct AlgoEntry g_algolist[];
extern const size_t g_algolist_size;
extern const struct AlgoEntry* g_algolist_end;
void SelectionSort(class WSortView& a);
void InsertionSort(class WSortView& a);
void BinaryInsertionSort(class WSortView& a);
void MergeSort(class WSortView& a);
wxArrayString QuickSortPivotText();
enum QuickSortPivotType { PIVOT_FIRST, PIVOT_LAST, PIVOT_MID, PIVOT_RANDOM, PIVOT_MEDIAN3 };
extern QuickSortPivotType g_quicksort_pivot;
void QuickSortLR(class WSortView& a);
void QuickSortLL(class WSortView& a);
void QuickSortTernaryLR(class WSortView& a);
void QuickSortTernaryLL(class WSortView& a);
void QuickSortDualPivot(class WSortView& a);
void BubbleSort(class WSortView& a);
void CocktailShakerSort(class WSortView& a);
void CombSort(class WSortView& a);
void GnomeSort(class WSortView& a);
void OddEvenSort(class WSortView& a);
void ShellSort(WSortView& a);
void HeapSort(class WSortView& a);
void SmoothSort(class WSortView& a);
void BitonicSort(WSortView& a);
void RadixSortLSD(class WSortView& a);
void RadixSortMSD(class WSortView& a);
void StlSort(class WSortView& a);
void StlStableSort(class WSortView& a);
void StlHeapSort(class WSortView& a);
void TimSort(class WSortView& a);
void WikiSort(class WSortView& a);
void BogoSort(class WSortView& a);
void BozoSort(class WSortView& a);
void StoogeSort(class WSortView& a);
void SlowSort(class WSortView& a);
void CycleSort(class WSortView& a);
class MyIterator : public std::iterator<std::random_access_iterator_tag, ArrayItem>
{
protected:
WSortView* m_array;
size_t m_pos;
public:
typedef std::iterator<std::random_access_iterator_tag, ArrayItem> base_type;
typedef std::random_access_iterator_tag iterator_category;
typedef base_type::value_type value_type;
typedef base_type::difference_type difference_type;
typedef base_type::reference reference;
typedef base_type::pointer pointer;
MyIterator() : m_array(NULL), m_pos(0) {}
MyIterator(WSortView* A, size_t p) : m_array(A), m_pos(p) {}
MyIterator(const MyIterator& r) : m_array(r.m_array), m_pos(r.m_pos) {}
MyIterator& operator=(const MyIterator& r)
{ m_array = r.m_array, m_pos = r.m_pos; return *this; }
MyIterator& operator++()
{ ++m_pos; return *this; }
MyIterator& operator--()
{ --m_pos; return *this; }
MyIterator operator++(int)
{ return MyIterator(m_array, m_pos++); }
MyIterator operator--(int)
{ return MyIterator(m_array, m_pos--); }
MyIterator operator+(const difference_type& n) const
{ return MyIterator(m_array, m_pos + n); }
MyIterator& operator+=(const difference_type& n)
{ m_pos += n; return *this; }
MyIterator operator-(const difference_type& n) const
{ return MyIterator(m_array, m_pos - n); }
MyIterator& operator-=(const difference_type& n)
{ m_pos -= n; return *this; }
reference operator*() const
{ return m_array->get_mutable(m_pos); }
pointer operator->() const
{ return &(m_array->get_mutable(m_pos)); }
reference operator[](const difference_type& n) const
{ return m_array->get_mutable(n); }
bool operator==(const MyIterator& r)
{ return (m_array == r.m_array) && (m_pos == r.m_pos); }
bool operator!=(const MyIterator& r)
{ return (m_array != r.m_array) || (m_pos != r.m_pos); }
bool operator<(const MyIterator& r)
{ return (m_array == r.m_array ? (m_pos < r.m_pos) : (m_array < r.m_array)); }
bool operator>(const MyIterator& r)
{ return (m_array == r.m_array ? (m_pos > r.m_pos) : (m_array > r.m_array)); }
bool operator<=(const MyIterator& r)
{ return (m_array == r.m_array ? (m_pos <= r.m_pos) : (m_array <= r.m_array)); }
bool operator>=(const MyIterator& r)
{ return (m_array == r.m_array ? (m_pos >= r.m_pos) : (m_array >= r.m_array)); }
difference_type operator+(const MyIterator& r2) const
{ ASSERT(m_array == r2.m_array); return (m_pos + r2.m_pos); }
difference_type operator-(const MyIterator& r2) const
{ ASSERT(m_array == r2.m_array); return (m_pos - r2.m_pos); }
};
#endif