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:
parent
28bf56e725
commit
04ff9c2548
1 changed files with 10 additions and 15 deletions
21
src/types.h
21
src/types.h
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue