1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-02 01:29:36 +00:00

Simplify our insertion sort implementation

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2012-01-22 22:53:57 +01:00
parent 28bf56e725
commit 04ff9c2548

View file

@ -485,22 +485,17 @@ inline const std::string square_to_string(Square s) {
/// Our insertion sort implementation, works with pointers and iterators and is
/// guaranteed to be stable, as is needed.
template<typename T, typename K>
void sort(K firstMove, K lastMove)
void sort(K first, K last)
{
T value;
K cur, p, d;
T tmp;
K p, q;
if (firstMove != lastMove)
for (cur = firstMove + 1; cur != lastMove; cur++)
for (p = first + 1; p < last; p++)
{
p = d = cur;
value = *p--;
if (*p < value)
{
do *d = *p;
while (--d != firstMove && *--p < value);
*d = value;
}
tmp = *p;
for (q = p; q != first && *(q-1) < tmp; --q)
*q = *(q-1);
*q = tmp;
}
}