1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:47:35 +00:00

AK: Add a basic QuickSort template implementation.

It was depressing not being able to capture anything when passing a lambda
to qsort_r() so let's just have our own QuickSort. I was gonna have to do
this eventually anyway. :^)
This commit is contained in:
Andreas Kling 2019-03-09 16:13:08 +01:00
parent e14dd06b8c
commit 0d5e6593b2
3 changed files with 61 additions and 16 deletions

View file

@ -274,7 +274,11 @@ public:
class Iterator {
public:
bool operator!=(const Iterator& other) { return m_index != other.m_index; }
bool operator==(const Iterator& other) { return m_index == other.m_index; }
bool operator<(const Iterator& other) { return m_index < other.m_index; }
Iterator& operator++() { ++m_index; return *this; }
Iterator operator-(int value) { return { m_vector, m_index - value }; }
Iterator operator+(int value) { return { m_vector, m_index + value }; }
T& operator*() { return m_vector[m_index]; }
private:
friend class Vector;
@ -289,7 +293,11 @@ public:
class ConstIterator {
public:
bool operator!=(const ConstIterator& other) { return m_index != other.m_index; }
bool operator==(const ConstIterator& other) { return m_index == other.m_index; }
bool operator<(const ConstIterator& other) { return m_index < other.m_index; }
ConstIterator& operator++() { ++m_index; return *this; }
ConstIterator operator-(int value) { return { m_vector, m_index - value }; }
ConstIterator operator+(int value) { return { m_vector, m_index + value }; }
const T& operator*() const { return m_vector[m_index]; }
private:
friend class Vector;