Created
January 30, 2019 20:50
-
-
Save Porges/c2e4a548af18b5ec684dcdd0e439d610 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void QuickSort<T>(FutureList<T> list) | |
where T: IComparable<T> | |
{ | |
QuickSort(list, list.FirstIndex, list.LastIndex); | |
} | |
void QuickSort<T>(FutureList<T> list, Index<T> lo, Index<T> hi) | |
where T : IComparable<T> | |
{ | |
if (lo < hi) | |
{ | |
var p = Partition(list, lo, hi); | |
QuickSort(list, lo, p - 1); | |
QuickSort(list, p + 1, hi); | |
} | |
} | |
Index<T> Partition<T>(FutureList<T> list, Index<T> lo, Index<T> hi) | |
where T : IComparable<T> | |
{ | |
var pivot = list[hi]; | |
var i = lo; | |
for (var j = lo; j < hi; j = j + 1) | |
{ | |
if (list[j].CompareTo(pivot) < 0) | |
{ | |
list.Swap(i, j); | |
i = i + 1; | |
} | |
} | |
list.Swap(i, hi); | |
return i; | |
} | |
struct Count<T> | |
{ | |
public static implicit operator Count<T>(int count) => throw new NotImplementedException(); // for now... | |
} | |
struct Index<T> | |
{ | |
public static bool operator <(Index<T> l, Index<T> r) => throw new NotImplementedException(); | |
public static bool operator >(Index<T> l, Index<T> r) => throw new NotImplementedException(); | |
public static Index<T> operator +(Index<T> l, Count<T> other) => throw new NotImplementedException(); | |
public static Index<T> operator -(Index<T> l, Count<T> other) => throw new NotImplementedException(); | |
} | |
class FutureList<T> | |
{ | |
public ref T this[Index<T> ix] => throw new NotImplementedException(); | |
public Index<T> FirstIndex => throw new NotImplementedException(); | |
public Index<T> LastIndex => throw new NotImplementedException(); | |
} | |
static class FutureListExtensions | |
{ | |
public static void Swap<T>(this FutureList<T> list, Index<T> i, Index<T> j) | |
{ | |
var tmp = list[i]; | |
list[i] = list[j]; | |
list[j] = tmp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment